Index: pdf/instance.cc |
diff --git a/pdf/instance.cc b/pdf/instance.cc |
index c796cd5588c103d8299890d5c4a7a26a4cb742c9..522029ff51f275d45f3b29cfa28a5d1050709035 100644 |
--- a/pdf/instance.cc |
+++ b/pdf/instance.cc |
@@ -107,6 +107,7 @@ const char kJSZoomOut[] = "zoomOut"; |
const char kDelimiters[] = "#&"; |
const char kNamedDest[] = "nameddest"; |
const char kPage[] = "page"; |
+const char kZoom[] = "zoom"; |
const char kChromePrint[] = "chrome://print/"; |
@@ -1506,6 +1507,8 @@ void Instance::DocumentLoadComplete(int page_count) { |
int initial_page = GetInitialPage(url_); |
if (initial_page >= 0) |
ScrollToPage(initial_page); |
+ |
+ HandleOpenParameters(url_); |
Lei Zhang
2014/07/30 02:43:20
Please note there is another call to GetInitialPag
|
} |
if (!full_) |
@@ -2322,6 +2325,67 @@ pp::URLLoader Instance::CreateURLLoaderInternal() { |
return loader; |
} |
+void Instance::HandleZoomParameter(const std::string& value) { |
raymes
2014/07/30 01:10:15
nit: value->url
|
+ std::vector<std::string> zoom_value; |
+ base::SplitString(value, ',', &zoom_value); |
+ // Only #zoom=scale or #zoom=scale,left,top are possible. |
+ if ((zoom_value.size() != 1) && (zoom_value.size() != 3)) |
+ return; |
+ |
+ const std::string& scale_string = zoom_value[0]; |
+ double scale_value; |
+ base::StringToDouble(scale_string, &scale_value); |
+ // User scale of 100 means zoom value of 100% i.e. zoom factor of 1.0. |
+ double zoom_factor = (scale_value / 100); |
raymes
2014/07/30 01:10:15
no need for ()
|
+ |
+ if (zoom_value.size() == 1) { |
+ // Handle #zoom=scale. |
+ SetZoom(ZOOM_SCALE, zoom_factor); |
+ return; |
+ } |
+ |
+ // Handle #zoom=scale,left,top. |
+ const std::string& left_string = zoom_value[1]; |
+ int left_value; |
+ base::StringToInt(left_string, &left_value); |
+ const std::string& top_string = zoom_value[2]; |
+ int top_value; |
+ base::StringToInt(top_string, &top_value); |
+ ScrollToX(left_value); |
+ ScrollToY(top_value); |
+ SetZoom(ZOOM_SCALE, zoom_factor); |
+} |
+ |
+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
|
+#if defined(OS_NACL) |
+ return; |
+#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
|
+ size_t found_idx = url.find('#'); |
+ if (found_idx == std::string::npos) |
+ return; |
+ |
+ const std::string& ref = url.substr(found_idx + 1); |
+ std::vector<std::string> fragments; |
+ Tokenize(ref, kDelimiters, &fragments); |
+ |
+ 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
|
+ std::vector<std::string> key_value; |
+ base::SplitString(fragments[i], '=', &key_value); |
+ if (key_value.size() != 2) |
+ continue; |
+ const std::string& key = key_value[0]; |
+ const std::string& value = key_value[1]; |
+ |
+ // Order is important as later actions can override effects |
+ // of previous actions. |
+ if (base::strcasecmp(kZoom, key.c_str()) == 0) { |
+ HandleZoomParameter(value); |
+ continue; |
+ } |
+ } |
+#endif |
+} |
+ |
int Instance::GetInitialPage(const std::string& url) { |
#if defined(OS_NACL) |
return -1; |