OLD | NEW |
---|---|
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/instance.h" | 5 #include "pdf/instance.h" |
6 | 6 |
7 #include <algorithm> // for min() | 7 #include <algorithm> // for min() |
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 const char kJSZoomFitToWidth[] = "fitToWidth"; | 100 const char kJSZoomFitToWidth[] = "fitToWidth"; |
101 const char kJSZoomIn[] = "zoomIn"; | 101 const char kJSZoomIn[] = "zoomIn"; |
102 const char kJSZoomOut[] = "zoomOut"; | 102 const char kJSZoomOut[] = "zoomOut"; |
103 | 103 |
104 // URL reference parameters. | 104 // URL reference parameters. |
105 // For more possible parameters, see RFC 3778 and the "PDF Open Parameters" | 105 // For more possible parameters, see RFC 3778 and the "PDF Open Parameters" |
106 // document from Adobe. | 106 // document from Adobe. |
107 const char kDelimiters[] = "#&"; | 107 const char kDelimiters[] = "#&"; |
108 const char kNamedDest[] = "nameddest"; | 108 const char kNamedDest[] = "nameddest"; |
109 const char kPage[] = "page"; | 109 const char kPage[] = "page"; |
110 const char kZoom[] = "zoom"; | |
110 | 111 |
111 const char kChromePrint[] = "chrome://print/"; | 112 const char kChromePrint[] = "chrome://print/"; |
112 | 113 |
113 // Dictionary Value key names for the document accessibility info | 114 // Dictionary Value key names for the document accessibility info |
114 const char kAccessibleNumberOfPages[] = "numberOfPages"; | 115 const char kAccessibleNumberOfPages[] = "numberOfPages"; |
115 const char kAccessibleLoaded[] = "loaded"; | 116 const char kAccessibleLoaded[] = "loaded"; |
116 const char kAccessibleCopyable[] = "copyable"; | 117 const char kAccessibleCopyable[] = "copyable"; |
117 | 118 |
118 const ToolbarButtonInfo kPDFToolbarButtons[] = { | 119 const ToolbarButtonInfo kPDFToolbarButtons[] = { |
119 { kFitToPageButtonId, Button::BUTTON_STATE, | 120 { kFitToPageButtonId, Button::BUTTON_STATE, |
(...skipping 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1499 UserMetricsRecordAction("PDF.LoadSuccess"); | 1500 UserMetricsRecordAction("PDF.LoadSuccess"); |
1500 if (on_load_callback_.is_string()) | 1501 if (on_load_callback_.is_string()) |
1501 ExecuteScript(on_load_callback_); | 1502 ExecuteScript(on_load_callback_); |
1502 // Note: If we are in print preview mode on_load_callback_ might call | 1503 // Note: If we are in print preview mode on_load_callback_ might call |
1503 // ScrollTo{X|Y}() and we don't want to scroll again and override it. | 1504 // ScrollTo{X|Y}() and we don't want to scroll again and override it. |
1504 // #page=N is not supported in Print Preview. | 1505 // #page=N is not supported in Print Preview. |
1505 if (!IsPrintPreview()) { | 1506 if (!IsPrintPreview()) { |
1506 int initial_page = GetInitialPage(url_); | 1507 int initial_page = GetInitialPage(url_); |
1507 if (initial_page >= 0) | 1508 if (initial_page >= 0) |
1508 ScrollToPage(initial_page); | 1509 ScrollToPage(initial_page); |
1510 | |
1511 HandleOpenParameters(url_); | |
Lei Zhang
2014/07/30 02:43:20
Please note there is another call to GetInitialPag
| |
1509 } | 1512 } |
1510 | 1513 |
1511 if (!full_) | 1514 if (!full_) |
1512 return; | 1515 return; |
1513 if (!pp::PDF::IsAvailable()) | 1516 if (!pp::PDF::IsAvailable()) |
1514 return; | 1517 return; |
1515 | 1518 |
1516 if (did_call_start_loading_) { | 1519 if (did_call_start_loading_) { |
1517 pp::PDF::DidStopLoading(this); | 1520 pp::PDF::DidStopLoading(this); |
1518 did_call_start_loading_ = false; | 1521 did_call_start_loading_ = false; |
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2315 | 2318 |
2316 const PPB_URLLoaderTrusted* trusted_interface = | 2319 const PPB_URLLoaderTrusted* trusted_interface = |
2317 reinterpret_cast<const PPB_URLLoaderTrusted*>( | 2320 reinterpret_cast<const PPB_URLLoaderTrusted*>( |
2318 pp::Module::Get()->GetBrowserInterface( | 2321 pp::Module::Get()->GetBrowserInterface( |
2319 PPB_URLLOADERTRUSTED_INTERFACE)); | 2322 PPB_URLLOADERTRUSTED_INTERFACE)); |
2320 if (trusted_interface) | 2323 if (trusted_interface) |
2321 trusted_interface->GrantUniversalAccess(loader.pp_resource()); | 2324 trusted_interface->GrantUniversalAccess(loader.pp_resource()); |
2322 return loader; | 2325 return loader; |
2323 } | 2326 } |
2324 | 2327 |
2328 void Instance::HandleZoomParameter(const std::string& value) { | |
raymes
2014/07/30 01:10:15
nit: value->url
| |
2329 std::vector<std::string> zoom_value; | |
2330 base::SplitString(value, ',', &zoom_value); | |
2331 // Only #zoom=scale or #zoom=scale,left,top are possible. | |
2332 if ((zoom_value.size() != 1) && (zoom_value.size() != 3)) | |
2333 return; | |
2334 | |
2335 const std::string& scale_string = zoom_value[0]; | |
2336 double scale_value; | |
2337 base::StringToDouble(scale_string, &scale_value); | |
2338 // User scale of 100 means zoom value of 100% i.e. zoom factor of 1.0. | |
2339 double zoom_factor = (scale_value / 100); | |
raymes
2014/07/30 01:10:15
no need for ()
| |
2340 | |
2341 if (zoom_value.size() == 1) { | |
2342 // Handle #zoom=scale. | |
2343 SetZoom(ZOOM_SCALE, zoom_factor); | |
2344 return; | |
2345 } | |
2346 | |
2347 // Handle #zoom=scale,left,top. | |
2348 const std::string& left_string = zoom_value[1]; | |
2349 int left_value; | |
2350 base::StringToInt(left_string, &left_value); | |
2351 const std::string& top_string = zoom_value[2]; | |
2352 int top_value; | |
2353 base::StringToInt(top_string, &top_value); | |
2354 ScrollToX(left_value); | |
2355 ScrollToY(top_value); | |
2356 SetZoom(ZOOM_SCALE, zoom_factor); | |
2357 } | |
2358 | |
2359 void Instance::HandleOpenParameters(const std::string& url) { | |
Lei Zhang
2014/07/30 02:43:21
Isn't this duplicating a good chunk of the code ri
| |
2360 #if defined(OS_NACL) | |
2361 return; | |
2362 #else | |
raymes
2014/07/30 01:10:15
You probably don't need this ifdef. I don't think
Lei Zhang
2014/07/30 02:43:21
raymes: If that is indeed the case, would you mind
| |
2363 size_t found_idx = url.find('#'); | |
2364 if (found_idx == std::string::npos) | |
2365 return; | |
2366 | |
2367 const std::string& ref = url.substr(found_idx + 1); | |
2368 std::vector<std::string> fragments; | |
2369 Tokenize(ref, kDelimiters, &fragments); | |
2370 | |
2371 for (size_t i = 0; i < fragments.size(); ++i) { | |
Lei Zhang
2014/07/30 02:43:20
What you really want to do is to scan the fragment
| |
2372 std::vector<std::string> key_value; | |
2373 base::SplitString(fragments[i], '=', &key_value); | |
2374 if (key_value.size() != 2) | |
2375 continue; | |
2376 const std::string& key = key_value[0]; | |
2377 const std::string& value = key_value[1]; | |
2378 | |
2379 // Order is important as later actions can override effects | |
2380 // of previous actions. | |
2381 if (base::strcasecmp(kZoom, key.c_str()) == 0) { | |
2382 HandleZoomParameter(value); | |
2383 continue; | |
2384 } | |
2385 } | |
2386 #endif | |
2387 } | |
2388 | |
2325 int Instance::GetInitialPage(const std::string& url) { | 2389 int Instance::GetInitialPage(const std::string& url) { |
2326 #if defined(OS_NACL) | 2390 #if defined(OS_NACL) |
2327 return -1; | 2391 return -1; |
2328 #else | 2392 #else |
2329 size_t found_idx = url.find('#'); | 2393 size_t found_idx = url.find('#'); |
2330 if (found_idx == std::string::npos) | 2394 if (found_idx == std::string::npos) |
2331 return -1; | 2395 return -1; |
2332 | 2396 |
2333 const std::string& ref = url.substr(found_idx + 1); | 2397 const std::string& ref = url.substr(found_idx + 1); |
2334 std::vector<std::string> fragments; | 2398 std::vector<std::string> fragments; |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2723 return instance_->HasScriptableMethod(name, exception); | 2787 return instance_->HasScriptableMethod(name, exception); |
2724 } | 2788 } |
2725 | 2789 |
2726 pp::Var PDFScriptableObject::Call(const pp::Var& method, | 2790 pp::Var PDFScriptableObject::Call(const pp::Var& method, |
2727 const std::vector<pp::Var>& args, | 2791 const std::vector<pp::Var>& args, |
2728 pp::Var* exception) { | 2792 pp::Var* exception) { |
2729 return instance_->CallScriptableMethod(method, args, exception); | 2793 return instance_->CallScriptableMethod(method, args, exception); |
2730 } | 2794 } |
2731 | 2795 |
2732 } // namespace chrome_pdf | 2796 } // namespace chrome_pdf |
OLD | NEW |