Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 476733003: OOP PDF - Add support for "page" open pdf parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback (nit fixes) Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "pdf/out_of_process_instance.h" 5 #include "pdf/out_of_process_instance.h"
6 6
7 #include <algorithm> // for min/max() 7 #include <algorithm> // for min/max()
8 #define _USE_MATH_DEFINES // for M_PI 8 #define _USE_MATH_DEFINES // for M_PI
9 #include <cmath> // for log() and pow() 9 #include <cmath> // for log() and pow()
10 #include <math.h> 10 #include <math.h>
(...skipping 30 matching lines...) Expand all
41 #include "ppapi/cpp/var_array.h" 41 #include "ppapi/cpp/var_array.h"
42 #include "ppapi/cpp/var_dictionary.h" 42 #include "ppapi/cpp/var_dictionary.h"
43 #include "ui/events/keycodes/keyboard_codes.h" 43 #include "ui/events/keycodes/keyboard_codes.h"
44 44
45 #if defined(OS_MACOSX) 45 #if defined(OS_MACOSX)
46 #include "base/mac/mac_util.h" 46 #include "base/mac/mac_util.h"
47 #endif 47 #endif
48 48
49 namespace chrome_pdf { 49 namespace chrome_pdf {
50 50
51 // URL reference parameters.
52 // For more possible parameters, see RFC 3778 and the "PDF Open Parameters"
53 // document from Adobe.
54 const char kDelimiters[] = "#&";
55 const char kNamedDest[] = "nameddest";
56 const char kPage[] = "page";
57
58 const char kChromePrint[] = "chrome://print/"; 51 const char kChromePrint[] = "chrome://print/";
59 const char kChromeExtension[] = 52 const char kChromeExtension[] =
60 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai"; 53 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai";
61 54
62 // Dictionary Value key names for the document accessibility info 55 // Dictionary Value key names for the document accessibility info
63 const char kAccessibleNumberOfPages[] = "numberOfPages"; 56 const char kAccessibleNumberOfPages[] = "numberOfPages";
64 const char kAccessibleLoaded[] = "loaded"; 57 const char kAccessibleLoaded[] = "loaded";
65 const char kAccessibleCopyable[] = "copyable"; 58 const char kAccessibleCopyable[] = "copyable";
66 59
67 // Constants used in handling postMessage() messages. 60 // Constants used in handling postMessage() messages.
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 void OutOfProcessInstance::DocumentLoadComplete(int page_count) { 1059 void OutOfProcessInstance::DocumentLoadComplete(int page_count) {
1067 // Clear focus state for OSK. 1060 // Clear focus state for OSK.
1068 FormTextFieldFocusChange(false); 1061 FormTextFieldFocusChange(false);
1069 1062
1070 DCHECK(document_load_state_ == LOAD_STATE_LOADING); 1063 DCHECK(document_load_state_ == LOAD_STATE_LOADING);
1071 document_load_state_ = LOAD_STATE_COMPLETE; 1064 document_load_state_ = LOAD_STATE_COMPLETE;
1072 UserMetricsRecordAction("PDF.LoadSuccess"); 1065 UserMetricsRecordAction("PDF.LoadSuccess");
1073 1066
1074 // Note: If we are in print preview mode the scroll location is retained 1067 // Note: If we are in print preview mode the scroll location is retained
1075 // across document loads so we don't want to scroll again and override it. 1068 // across document loads so we don't want to scroll again and override it.
1076 if (!IsPrintPreview()) { 1069 if (IsPrintPreview()) {
1077 int initial_page = GetInitialPage(url_);
1078 if (initial_page >= 0)
1079 ScrollToPage(initial_page);
1080 } else {
1081 AppendBlankPrintPreviewPages(); 1070 AppendBlankPrintPreviewPages();
1082 OnGeometryChanged(0, 0); 1071 OnGeometryChanged(0, 0);
1083 } 1072 }
1084 1073
1085 pp::VarDictionary message; 1074 pp::VarDictionary message;
1086 message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); 1075 message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType));
1087 message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)) ; 1076 message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)) ;
1088 PostMessage(message); 1077 PostMessage(message);
1089 1078
1090 if (!full_) 1079 if (!full_)
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 1286
1298 const PPB_URLLoaderTrusted* trusted_interface = 1287 const PPB_URLLoaderTrusted* trusted_interface =
1299 reinterpret_cast<const PPB_URLLoaderTrusted*>( 1288 reinterpret_cast<const PPB_URLLoaderTrusted*>(
1300 pp::Module::Get()->GetBrowserInterface( 1289 pp::Module::Get()->GetBrowserInterface(
1301 PPB_URLLOADERTRUSTED_INTERFACE)); 1290 PPB_URLLOADERTRUSTED_INTERFACE));
1302 if (trusted_interface) 1291 if (trusted_interface)
1303 trusted_interface->GrantUniversalAccess(loader.pp_resource()); 1292 trusted_interface->GrantUniversalAccess(loader.pp_resource());
1304 return loader; 1293 return loader;
1305 } 1294 }
1306 1295
1307 int OutOfProcessInstance::GetInitialPage(const std::string& url) {
1308 size_t found_idx = url.find('#');
1309 if (found_idx == std::string::npos)
1310 return -1;
1311
1312 const std::string& ref = url.substr(found_idx + 1);
1313 std::vector<std::string> fragments;
1314 Tokenize(ref, kDelimiters, &fragments);
1315
1316 // Page number to return, zero-based.
1317 int page = -1;
1318
1319 // Handle the case of http://foo.com/bar#NAMEDDEST. This is not explicitly
1320 // mentioned except by example in the Adobe "PDF Open Parameters" document.
1321 if ((fragments.size() == 1) && (fragments[0].find('=') == std::string::npos))
1322 return engine_->GetNamedDestinationPage(fragments[0]);
1323
1324 for (size_t i = 0; i < fragments.size(); ++i) {
1325 std::vector<std::string> key_value;
1326 base::SplitString(fragments[i], '=', &key_value);
1327 if (key_value.size() != 2)
1328 continue;
1329 const std::string& key = key_value[0];
1330 const std::string& value = key_value[1];
1331
1332 if (base::strcasecmp(kPage, key.c_str()) == 0) {
1333 // |page_value| is 1-based.
1334 int page_value = -1;
1335 if (base::StringToInt(value, &page_value) && page_value > 0)
1336 page = page_value - 1;
1337 continue;
1338 }
1339 if (base::strcasecmp(kNamedDest, key.c_str()) == 0) {
1340 // |page_value| is 0-based.
1341 int page_value = engine_->GetNamedDestinationPage(value);
1342 if (page_value >= 0)
1343 page = page_value;
1344 continue;
1345 }
1346 }
1347 return page;
1348 }
1349
1350 void OutOfProcessInstance::SetZoom(double scale) { 1296 void OutOfProcessInstance::SetZoom(double scale) {
1351 double old_zoom = zoom_; 1297 double old_zoom = zoom_;
1352 zoom_ = scale; 1298 zoom_ = scale;
1353 OnGeometryChanged(old_zoom, device_scale_); 1299 OnGeometryChanged(old_zoom, device_scale_);
1354 } 1300 }
1355 1301
1356 std::string OutOfProcessInstance::GetLocalizedString(PP_ResourceString id) { 1302 std::string OutOfProcessInstance::GetLocalizedString(PP_ResourceString id) {
1357 pp::Var rv(pp::PDF::GetLocalizedString(this, id)); 1303 pp::Var rv(pp::PDF::GetLocalizedString(this, id));
1358 if (!rv.is_string()) 1304 if (!rv.is_string())
1359 return std::string(); 1305 return std::string();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument( 1360 pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument(
1415 const pp::Point& scroll_offset) { 1361 const pp::Point& scroll_offset) {
1416 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1362 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1417 int x = std::max(std::min(scroll_offset.x(), max_x), 0); 1363 int x = std::max(std::min(scroll_offset.x(), max_x), 0);
1418 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1364 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1419 int y = std::max(std::min(scroll_offset.y(), max_y), 0); 1365 int y = std::max(std::min(scroll_offset.y(), max_y), 0);
1420 return pp::Point(x, y); 1366 return pp::Point(x, y);
1421 } 1367 }
1422 1368
1423 } // namespace chrome_pdf 1369 } // namespace chrome_pdf
OLDNEW
« chrome/browser/resources/pdf/pdf.js ('K') | « chrome/browser/resources/pdf/pdf.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698