Chromium Code Reviews| 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/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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 RemovePerInstanceObject(kPPPPdfInterface, this); | 298 RemovePerInstanceObject(kPPPPdfInterface, this); |
| 299 // Explicitly reset the PDFEngine during destruction as it may call back into | 299 // Explicitly reset the PDFEngine during destruction as it may call back into |
| 300 // this object. | 300 // this object. |
| 301 engine_.reset(); | 301 engine_.reset(); |
| 302 } | 302 } |
| 303 | 303 |
| 304 bool OutOfProcessInstance::Init(uint32_t argc, | 304 bool OutOfProcessInstance::Init(uint32_t argc, |
| 305 const char* argn[], | 305 const char* argn[], |
| 306 const char* argv[]) { | 306 const char* argv[]) { |
| 307 // Check if the PDF is being loaded in the PDF chrome extension. We only allow | 307 // Check if the PDF is being loaded in the PDF chrome extension. We only allow |
| 308 // the plugin to be put into "full frame" mode when it is being loaded in the | 308 // the plugin to be loaded in the extension to avoid exposing sensitive APIs |
|
Sam McNally
2015/08/25 03:11:20
And print preview?
raymes
2015/08/25 04:02:23
Done.
| |
| 309 // extension because this enables some features that we don't want pages | 309 // directly to external websites. |
| 310 // abusing outside of the extension. | |
| 311 pp::Var document_url_var = pp::URLUtil_Dev::Get()->GetDocumentURL(this); | 310 pp::Var document_url_var = pp::URLUtil_Dev::Get()->GetDocumentURL(this); |
| 312 std::string document_url = document_url_var.is_string() ? | 311 std::string document_url = document_url_var.is_string() ? |
|
Sam McNally
2015/08/25 03:11:20
if (!document_url_var.is_string())
return false;
raymes
2015/08/25 04:02:23
Done.
| |
| 313 document_url_var.AsString() : std::string(); | 312 document_url_var.AsString() : std::string(); |
| 314 std::string extension_url = std::string(kChromeExtension); | 313 std::string extension_url = std::string(kChromeExtension); |
| 315 bool in_extension = | 314 std::string print_preview_url = std::string(kChromePrint); |
| 316 !document_url.compare(0, extension_url.size(), extension_url); | 315 bool allowed = |
| 316 !document_url.compare(0, extension_url.size(), extension_url) || | |
|
Sam McNally
2015/08/25 03:11:20
if (!base::StringPiece(document_url).starts_with(k
raymes
2015/08/25 04:02:23
Done.
| |
| 317 !document_url.compare(0, print_preview_url.size(), print_preview_url); | |
| 317 | 318 |
| 318 if (in_extension) { | 319 if (!allowed) |
| 319 // Check if the plugin is full frame. This is passed in from JS. | 320 return false; |
| 320 for (uint32_t i = 0; i < argc; ++i) { | 321 |
| 321 if (strcmp(argn[i], "full-frame") == 0) { | 322 // Check if the plugin is full frame. This is passed in from JS. |
| 322 full_ = true; | 323 for (uint32_t i = 0; i < argc; ++i) { |
| 323 break; | 324 if (strcmp(argn[i], "full-frame") == 0) { |
| 324 } | 325 full_ = true; |
| 326 break; | |
| 325 } | 327 } |
| 326 } | 328 } |
| 327 | 329 |
| 328 // Only allow the plugin to handle find requests if it is full frame. | 330 // Only allow the plugin to handle find requests if it is full frame. |
| 329 if (full_) | 331 if (full_) |
| 330 SetPluginToHandleFindRequests(); | 332 SetPluginToHandleFindRequests(); |
| 331 | 333 |
| 332 // Send translated strings to the extension where they will be displayed. | 334 // Send translated strings to the extension where they will be displayed. |
| 333 // TODO(raymes): It would be better to get these in the extension directly | 335 // TODO(raymes): It would be better to get these in the extension directly |
| 334 // through an API but no such API currently exists. | 336 // through an API but no such API currently exists. |
| (...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1430 const pp::FloatPoint& scroll_offset) { | 1432 const pp::FloatPoint& scroll_offset) { |
| 1431 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1433 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
| 1432 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); | 1434 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
| 1433 float min_y = -top_toolbar_height_; | 1435 float min_y = -top_toolbar_height_; |
| 1434 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1436 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
| 1435 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); | 1437 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); |
| 1436 return pp::FloatPoint(x, y); | 1438 return pp::FloatPoint(x, y); |
| 1437 } | 1439 } |
| 1438 | 1440 |
| 1439 } // namespace chrome_pdf | 1441 } // namespace chrome_pdf |
| OLD | NEW |