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

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 2837663002: Cleanup PDF plugin code. (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « pdf/out_of_process_instance.h ('k') | pdf/pdf_engine.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> // for min/max() 10 #include <algorithm> // for min/max()
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 print_preview_page_count_(0), 292 print_preview_page_count_(0),
293 last_progress_sent_(0), 293 last_progress_sent_(0),
294 recently_sent_find_update_(false), 294 recently_sent_find_update_(false),
295 received_viewport_message_(false), 295 received_viewport_message_(false),
296 did_call_start_loading_(false), 296 did_call_start_loading_(false),
297 stop_scrolling_(false), 297 stop_scrolling_(false),
298 background_color_(0), 298 background_color_(0),
299 top_toolbar_height_(0), 299 top_toolbar_height_(0),
300 accessibility_state_(ACCESSIBILITY_STATE_OFF), 300 accessibility_state_(ACCESSIBILITY_STATE_OFF),
301 is_print_preview_(false) { 301 is_print_preview_(false) {
302 loader_factory_.Initialize(this); 302 callback_factory_.Initialize(this);
303 timer_factory_.Initialize(this); 303 engine_ = PDFEngine::Create(this);
304 form_factory_.Initialize(this);
305 print_callback_factory_.Initialize(this);
306 engine_.reset(PDFEngine::Create(this));
307 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); 304 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private);
308 AddPerInstanceObject(kPPPPdfInterface, this); 305 AddPerInstanceObject(kPPPPdfInterface, this);
309 306
310 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); 307 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
311 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); 308 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
312 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_TOUCH); 309 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_TOUCH);
313 } 310 }
314 311
315 OutOfProcessInstance::~OutOfProcessInstance() { 312 OutOfProcessInstance::~OutOfProcessInstance() {
316 RemovePerInstanceObject(kPPPPdfInterface, this); 313 RemovePerInstanceObject(kPPPPdfInterface, this);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 if (!stream_url) 375 if (!stream_url)
379 stream_url = original_url; 376 stream_url = original_url;
380 377
381 // If we're in print preview mode we don't need to load the document yet. 378 // If we're in print preview mode we don't need to load the document yet.
382 // A |kJSResetPrintPreviewModeType| message will be sent to the plugin letting 379 // A |kJSResetPrintPreviewModeType| message will be sent to the plugin letting
383 // it know the url to load. By not loading here we avoid loading the same 380 // it know the url to load. By not loading here we avoid loading the same
384 // document twice. 381 // document twice.
385 if (IsPrintPreview()) 382 if (IsPrintPreview())
386 return true; 383 return true;
387 384
388 LoadUrl(stream_url); 385 LoadUrl(stream_url, false /* is_print_preview */);
raymes 2017/04/26 02:44:19 I just had advice from thakis@ that /*is_print_pre
Lei Zhang 2017/05/04 17:39:28 Done.
389 url_ = original_url; 386 url_ = original_url;
390 pp::PDF::SetCrashData(GetPluginInstance(), original_url, top_level_url); 387 pp::PDF::SetCrashData(GetPluginInstance(), original_url, top_level_url);
391 return engine_->New(original_url, headers); 388 return engine_->New(original_url, headers);
392 } 389 }
393 390
394 void OutOfProcessInstance::HandleMessage(const pp::Var& message) { 391 void OutOfProcessInstance::HandleMessage(const pp::Var& message) {
395 pp::VarDictionary dict(message); 392 pp::VarDictionary dict(message);
396 if (!dict.Get(kType).is_string()) { 393 if (!dict.Get(kType).is_string()) {
397 NOTREACHED(); 394 NOTREACHED();
398 return; 395 return;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 dict.Get(pp::Var(kJSPrintPreviewGrayscale)).is_bool() && 526 dict.Get(pp::Var(kJSPrintPreviewGrayscale)).is_bool() &&
530 dict.Get(pp::Var(kJSPrintPreviewPageCount)).is_int()) { 527 dict.Get(pp::Var(kJSPrintPreviewPageCount)).is_int()) {
531 url_ = dict.Get(pp::Var(kJSPrintPreviewUrl)).AsString(); 528 url_ = dict.Get(pp::Var(kJSPrintPreviewUrl)).AsString();
532 // For security reasons we crash if the URL that is trying to be loaded here 529 // For security reasons we crash if the URL that is trying to be loaded here
533 // isn't a print preview one. 530 // isn't a print preview one.
534 CHECK(IsPrintPreview()); 531 CHECK(IsPrintPreview());
535 CHECK(IsPrintPreviewUrl(url_)); 532 CHECK(IsPrintPreviewUrl(url_));
536 preview_pages_info_ = std::queue<PreviewPageInfo>(); 533 preview_pages_info_ = std::queue<PreviewPageInfo>();
537 preview_document_load_state_ = LOAD_STATE_COMPLETE; 534 preview_document_load_state_ = LOAD_STATE_COMPLETE;
538 document_load_state_ = LOAD_STATE_LOADING; 535 document_load_state_ = LOAD_STATE_LOADING;
539 LoadUrl(url_); 536 LoadUrl(url_, false /* is_print_preview */);
540 preview_engine_.reset(); 537 preview_engine_.reset();
541 engine_.reset(PDFEngine::Create(this)); 538 engine_ = PDFEngine::Create(this);
542 engine_->SetGrayscale(dict.Get(pp::Var(kJSPrintPreviewGrayscale)).AsBool()); 539 engine_->SetGrayscale(dict.Get(pp::Var(kJSPrintPreviewGrayscale)).AsBool());
543 engine_->New(url_.c_str(), nullptr /* empty header */); 540 engine_->New(url_.c_str(), nullptr /* empty header */);
544 541
545 print_preview_page_count_ = 542 print_preview_page_count_ =
546 std::max(dict.Get(pp::Var(kJSPrintPreviewPageCount)).AsInt(), 0); 543 std::max(dict.Get(pp::Var(kJSPrintPreviewPageCount)).AsInt(), 0);
547 544
548 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); 545 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_));
549 } else if (type == kJSLoadPreviewPageType && 546 } else if (type == kJSLoadPreviewPageType &&
550 dict.Get(pp::Var(kJSPreviewPageUrl)).is_string() && 547 dict.Get(pp::Var(kJSPreviewPageUrl)).is_string() &&
551 dict.Get(pp::Var(kJSPreviewPageIndex)).is_int()) { 548 dict.Get(pp::Var(kJSPreviewPageIndex)).is_int()) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 709
713 // If the document contents isn't accessible, don't send anything more. 710 // If the document contents isn't accessible, don't send anything more.
714 if (!(engine_->HasPermission(PDFEngine::PERMISSION_COPY) || 711 if (!(engine_->HasPermission(PDFEngine::PERMISSION_COPY) ||
715 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE))) { 712 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE))) {
716 return; 713 return;
717 } 714 }
718 715
719 SendAccessibilityViewportInfo(); 716 SendAccessibilityViewportInfo();
720 717
721 // Schedule loading the first page. 718 // Schedule loading the first page.
722 pp::CompletionCallback callback = timer_factory_.NewCallback( 719 pp::CompletionCallback callback = callback_factory_.NewCallback(
723 &OutOfProcessInstance::SendNextAccessibilityPage); 720 &OutOfProcessInstance::SendNextAccessibilityPage);
724 pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs, 721 pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs,
725 callback, 0); 722 callback, 0);
726 } 723 }
727 724
728 void OutOfProcessInstance::SendNextAccessibilityPage(int32_t page_index) { 725 void OutOfProcessInstance::SendNextAccessibilityPage(int32_t page_index) {
729 int page_count = engine_->GetNumberOfPages(); 726 int page_count = engine_->GetNumberOfPages();
730 if (page_index < 0 || page_index >= page_count) 727 if (page_index < 0 || page_index >= page_count)
731 return; 728 return;
732 729
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 chars[char_index + text_run_info.len - 1].char_width = char_bounds.width(); 775 chars[char_index + text_run_info.len - 1].char_width = char_bounds.width();
779 776
780 char_index += text_run_info.len; 777 char_index += text_run_info.len;
781 } 778 }
782 779
783 page_info.text_run_count = text_runs.size(); 780 page_info.text_run_count = text_runs.size();
784 pp::PDF::SetAccessibilityPageInfo(GetPluginInstance(), &page_info, 781 pp::PDF::SetAccessibilityPageInfo(GetPluginInstance(), &page_info,
785 text_runs.data(), chars.data()); 782 text_runs.data(), chars.data());
786 783
787 // Schedule loading the next page. 784 // Schedule loading the next page.
788 pp::CompletionCallback callback = timer_factory_.NewCallback( 785 pp::CompletionCallback callback = callback_factory_.NewCallback(
789 &OutOfProcessInstance::SendNextAccessibilityPage); 786 &OutOfProcessInstance::SendNextAccessibilityPage);
790 pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs, 787 pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs,
791 callback, page_index + 1); 788 callback, page_index + 1);
792 } 789 }
793 790
794 void OutOfProcessInstance::SendAccessibilityViewportInfo() { 791 void OutOfProcessInstance::SendAccessibilityViewportInfo() {
795 PP_PrivateAccessibilityViewportInfo viewport_info; 792 PP_PrivateAccessibilityViewportInfo viewport_info;
796 viewport_info.scroll.x = 0; 793 viewport_info.scroll.x = 0;
797 viewport_info.scroll.y = -top_toolbar_height_ * device_scale_; 794 viewport_info.scroll.y = -top_toolbar_height_ * device_scale_;
798 viewport_info.offset = available_area_.point(); 795 viewport_info.offset = available_area_.point();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 if (engine_->IsProgressiveLoad()) { 949 if (engine_->IsProgressiveLoad()) {
953 pp::VarDictionary message; 950 pp::VarDictionary message;
954 message.Set(kType, kJSCancelStreamUrlType); 951 message.Set(kType, kJSCancelStreamUrlType);
955 PostMessage(message); 952 PostMessage(message);
956 } 953 }
957 } 954 }
958 955
959 void OutOfProcessInstance::DidOpenPreview(int32_t result) { 956 void OutOfProcessInstance::DidOpenPreview(int32_t result) {
960 if (result == PP_OK) { 957 if (result == PP_OK) {
961 preview_client_ = base::MakeUnique<PreviewModeClient>(this); 958 preview_client_ = base::MakeUnique<PreviewModeClient>(this);
962 preview_engine_.reset(PDFEngine::Create(preview_client_.get())); 959 preview_engine_ = PDFEngine::Create(preview_client_.get());
963 preview_engine_->HandleDocumentLoad(embed_preview_loader_); 960 preview_engine_->HandleDocumentLoad(embed_preview_loader_);
964 } else { 961 } else {
965 NOTREACHED(); 962 NOTREACHED();
966 } 963 }
967 } 964 }
968 965
969 void OutOfProcessInstance::OnClientTimerFired(int32_t id) { 966 void OutOfProcessInstance::OnClientTimerFired(int32_t id) {
970 engine_->OnCallback(id); 967 engine_->OnCallback(id);
971 } 968 }
972 969
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 SetTickmarks(tickmarks_); 1117 SetTickmarks(tickmarks_);
1121 return; 1118 return;
1122 } 1119 }
1123 1120
1124 if (recently_sent_find_update_) 1121 if (recently_sent_find_update_)
1125 return; 1122 return;
1126 1123
1127 NumberOfFindResultsChanged(total, final_result); 1124 NumberOfFindResultsChanged(total, final_result);
1128 SetTickmarks(tickmarks_); 1125 SetTickmarks(tickmarks_);
1129 recently_sent_find_update_ = true; 1126 recently_sent_find_update_ = true;
1130 pp::CompletionCallback callback = timer_factory_.NewCallback( 1127 pp::CompletionCallback callback = callback_factory_.NewCallback(
1131 &OutOfProcessInstance::ResetRecentlySentFindUpdate); 1128 &OutOfProcessInstance::ResetRecentlySentFindUpdate);
1132 pp::Module::Get()->core()->CallOnMainThread(kFindResultCooldownMs, callback, 1129 pp::Module::Get()->core()->CallOnMainThread(kFindResultCooldownMs, callback,
1133 0); 1130 0);
1134 } 1131 }
1135 1132
1136 void OutOfProcessInstance::NotifySelectedFindResultChanged( 1133 void OutOfProcessInstance::NotifySelectedFindResultChanged(
1137 int current_find_index) { 1134 int current_find_index) {
1138 DCHECK_GE(current_find_index, 0); 1135 DCHECK_GE(current_find_index, 0);
1139 SelectedFindResultChanged(current_find_index); 1136 SelectedFindResultChanged(current_find_index);
1140 } 1137 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 PostMessage(message); 1189 PostMessage(message);
1193 } 1190 }
1194 1191
1195 void OutOfProcessInstance::Print() { 1192 void OutOfProcessInstance::Print() {
1196 if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) && 1193 if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) &&
1197 !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) { 1194 !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) {
1198 return; 1195 return;
1199 } 1196 }
1200 1197
1201 pp::CompletionCallback callback = 1198 pp::CompletionCallback callback =
1202 print_callback_factory_.NewCallback(&OutOfProcessInstance::OnPrint); 1199 callback_factory_.NewCallback(&OutOfProcessInstance::OnPrint);
1203 pp::Module::Get()->core()->CallOnMainThread(0, callback); 1200 pp::Module::Get()->core()->CallOnMainThread(0, callback);
1204 } 1201 }
1205 1202
1206 void OutOfProcessInstance::OnPrint(int32_t) { 1203 void OutOfProcessInstance::OnPrint(int32_t) {
1207 pp::PDF::Print(this); 1204 pp::PDF::Print(this);
1208 } 1205 }
1209 1206
1210 void OutOfProcessInstance::SubmitForm(const std::string& url, 1207 void OutOfProcessInstance::SubmitForm(const std::string& url,
1211 const void* data, 1208 const void* data,
1212 int length) { 1209 int length) {
1213 pp::URLRequestInfo request(this); 1210 pp::URLRequestInfo request(this);
1214 request.SetURL(url); 1211 request.SetURL(url);
1215 request.SetMethod("POST"); 1212 request.SetMethod("POST");
1216 request.AppendDataToBody(reinterpret_cast<const char*>(data), length); 1213 request.AppendDataToBody(reinterpret_cast<const char*>(data), length);
1217 1214
1218 pp::CompletionCallback callback = 1215 pp::CompletionCallback callback =
1219 form_factory_.NewCallback(&OutOfProcessInstance::FormDidOpen); 1216 callback_factory_.NewCallback(&OutOfProcessInstance::FormDidOpen);
1220 form_loader_ = CreateURLLoaderInternal(); 1217 form_loader_ = CreateURLLoaderInternal();
1221 int rv = form_loader_.Open(request, callback); 1218 int rv = form_loader_.Open(request, callback);
1222 if (rv != PP_OK_COMPLETIONPENDING) 1219 if (rv != PP_OK_COMPLETIONPENDING)
1223 callback.Run(rv); 1220 callback.Run(rv);
1224 } 1221 }
1225 1222
1226 void OutOfProcessInstance::FormDidOpen(int32_t result) { 1223 void OutOfProcessInstance::FormDidOpen(int32_t result) {
1227 // TODO: inform the user of success/failure. 1224 // TODO: inform the user of success/failure.
1228 if (result != PP_OK) { 1225 if (result != PP_OK) {
1229 NOTREACHED(); 1226 NOTREACHED();
(...skipping 19 matching lines...) Expand all
1249 // call DidStartLoading since that resets the content restrictions. 1246 // call DidStartLoading since that resets the content restrictions.
1250 pp::PDF::SetContentRestriction( 1247 pp::PDF::SetContentRestriction(
1251 this, CONTENT_RESTRICTION_SAVE | CONTENT_RESTRICTION_PRINT); 1248 this, CONTENT_RESTRICTION_SAVE | CONTENT_RESTRICTION_PRINT);
1252 } 1249 }
1253 1250
1254 return CreateURLLoaderInternal(); 1251 return CreateURLLoaderInternal();
1255 } 1252 }
1256 1253
1257 void OutOfProcessInstance::ScheduleCallback(int id, int delay_in_ms) { 1254 void OutOfProcessInstance::ScheduleCallback(int id, int delay_in_ms) {
1258 pp::CompletionCallback callback = 1255 pp::CompletionCallback callback =
1259 timer_factory_.NewCallback(&OutOfProcessInstance::OnClientTimerFired); 1256 callback_factory_.NewCallback(&OutOfProcessInstance::OnClientTimerFired);
1260 pp::Module::Get()->core()->CallOnMainThread(delay_in_ms, callback, id); 1257 pp::Module::Get()->core()->CallOnMainThread(delay_in_ms, callback, id);
1261 } 1258 }
1262 1259
1263 void OutOfProcessInstance::SearchString( 1260 void OutOfProcessInstance::SearchString(
1264 const base::char16* string, 1261 const base::char16* string,
1265 const base::char16* term, 1262 const base::char16* term,
1266 bool case_sensitive, 1263 bool case_sensitive,
1267 std::vector<SearchStringResult>* results) { 1264 std::vector<SearchStringResult>* results) {
1268 PP_PrivateFindResult* pp_results; 1265 PP_PrivateFindResult* pp_results;
1269 int count = 0; 1266 int count = 0;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 } 1355 }
1359 1356
1360 void OutOfProcessInstance::PreviewDocumentLoadComplete() { 1357 void OutOfProcessInstance::PreviewDocumentLoadComplete() {
1361 if (preview_document_load_state_ != LOAD_STATE_LOADING || 1358 if (preview_document_load_state_ != LOAD_STATE_LOADING ||
1362 preview_pages_info_.empty()) { 1359 preview_pages_info_.empty()) {
1363 return; 1360 return;
1364 } 1361 }
1365 1362
1366 preview_document_load_state_ = LOAD_STATE_COMPLETE; 1363 preview_document_load_state_ = LOAD_STATE_COMPLETE;
1367 1364
1365 const std::string& url = preview_pages_info_.front().first;
1368 int dest_page_index = preview_pages_info_.front().second; 1366 int dest_page_index = preview_pages_info_.front().second;
1369 int src_page_index = 1367 int src_page_index = ExtractPrintPreviewPageIndex(url);
1370 ExtractPrintPreviewPageIndex(preview_pages_info_.front().first); 1368 if (src_page_index > 0 && dest_page_index > -1 && preview_engine_)
1371 if (src_page_index > 0 && dest_page_index > -1 && preview_engine_.get())
1372 engine_->AppendPage(preview_engine_.get(), dest_page_index); 1369 engine_->AppendPage(preview_engine_.get(), dest_page_index);
1373 1370
1374 preview_pages_info_.pop(); 1371 preview_pages_info_.pop();
1375 // |print_preview_page_count_| is not updated yet. Do not load any 1372 // |print_preview_page_count_| is not updated yet. Do not load any
1376 // other preview pages till we get this information. 1373 // other preview pages until this information is available.
1377 if (print_preview_page_count_ == 0) 1374 if (print_preview_page_count_ == 0)
1378 return; 1375 return;
1379 1376
1380 if (!preview_pages_info_.empty()) 1377 if (!preview_pages_info_.empty())
1381 LoadAvailablePreviewPage(); 1378 LoadAvailablePreviewPage();
1382 } 1379 }
1383 1380
1384 void OutOfProcessInstance::DocumentLoadFailed() { 1381 void OutOfProcessInstance::DocumentLoadFailed() {
1385 DCHECK_EQ(LOAD_STATE_LOADING, document_load_state_); 1382 DCHECK_EQ(LOAD_STATE_LOADING, document_load_state_);
1386 UserMetricsRecordAction("PDF.LoadFailure"); 1383 UserMetricsRecordAction("PDF.LoadFailure");
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 if (progress > last_progress_sent_ + 1) { 1463 if (progress > last_progress_sent_ + 1) {
1467 last_progress_sent_ = progress; 1464 last_progress_sent_ = progress;
1468 pp::VarDictionary message; 1465 pp::VarDictionary message;
1469 message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); 1466 message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType));
1470 message.Set(pp::Var(kJSProgressPercentage), pp::Var(progress)); 1467 message.Set(pp::Var(kJSProgressPercentage), pp::Var(progress));
1471 PostMessage(message); 1468 PostMessage(message);
1472 } 1469 }
1473 } 1470 }
1474 1471
1475 void OutOfProcessInstance::FormTextFieldFocusChange(bool in_focus) { 1472 void OutOfProcessInstance::FormTextFieldFocusChange(bool in_focus) {
1476 if (!text_input_.get()) 1473 if (!text_input_)
1477 return; 1474 return;
1478 1475
1479 pp::VarDictionary message; 1476 pp::VarDictionary message;
1480 message.Set(pp::Var(kType), pp::Var(kJSFieldFocusType)); 1477 message.Set(pp::Var(kType), pp::Var(kJSFieldFocusType));
1481 message.Set(pp::Var(kJSFieldFocus), pp::Var(in_focus)); 1478 message.Set(pp::Var(kJSFieldFocus), pp::Var(in_focus));
1482 PostMessage(message); 1479 PostMessage(message);
1483 1480
1484 text_input_->SetTextInputType(in_focus ? PP_TEXTINPUT_TYPE_DEV_TEXT 1481 text_input_->SetTextInputType(in_focus ? PP_TEXTINPUT_TYPE_DEV_TEXT
1485 : PP_TEXTINPUT_TYPE_DEV_NONE); 1482 : PP_TEXTINPUT_TYPE_DEV_NONE);
1486 } 1483 }
(...skipping 23 matching lines...) Expand all
1510 engine_->PluginSizeUpdated(available_area_.size()); 1507 engine_->PluginSizeUpdated(available_area_.size());
1511 1508
1512 if (document_size_.IsEmpty()) 1509 if (document_size_.IsEmpty())
1513 return; 1510 return;
1514 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); 1511 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_));
1515 1512
1516 if (accessibility_state_ == ACCESSIBILITY_STATE_LOADED) 1513 if (accessibility_state_ == ACCESSIBILITY_STATE_LOADED)
1517 SendAccessibilityViewportInfo(); 1514 SendAccessibilityViewportInfo();
1518 } 1515 }
1519 1516
1520 void OutOfProcessInstance::LoadUrl(const std::string& url) { 1517 void OutOfProcessInstance::LoadUrl(const std::string& url,
1521 LoadUrlInternal(url, &embed_loader_, &OutOfProcessInstance::DidOpen); 1518 bool is_print_preview) {
1522 }
1523
1524 void OutOfProcessInstance::LoadPreviewUrl(const std::string& url) {
1525 LoadUrlInternal(url, &embed_preview_loader_,
1526 &OutOfProcessInstance::DidOpenPreview);
1527 }
1528
1529 void OutOfProcessInstance::LoadUrlInternal(
1530 const std::string& url,
1531 pp::URLLoader* loader,
1532 void (OutOfProcessInstance::*method)(int32_t)) {
1533 pp::URLRequestInfo request(this); 1519 pp::URLRequestInfo request(this);
1534 request.SetURL(url); 1520 request.SetURL(url);
1535 request.SetMethod("GET"); 1521 request.SetMethod("GET");
1536 request.SetFollowRedirects(false); 1522 request.SetFollowRedirects(false);
1537 1523
1538 *loader = CreateURLLoaderInternal(); 1524 pp::URLLoader& loader =
1539 pp::CompletionCallback callback = loader_factory_.NewCallback(method); 1525 is_print_preview ? embed_preview_loader_ : embed_loader_;
raymes 2017/04/26 02:44:19 This is a bit subtle to me. Maybe it's just becaus
Lei Zhang 2017/05/04 17:39:28 Back to pointers.
1540 int rv = loader->Open(request, callback); 1526 loader = CreateURLLoaderInternal();
1527 pp::CompletionCallback callback = callback_factory_.NewCallback(
1528 is_print_preview ? &OutOfProcessInstance::DidOpenPreview
1529 : &OutOfProcessInstance::DidOpen);
1530 int rv = loader.Open(request, callback);
1541 if (rv != PP_OK_COMPLETIONPENDING) 1531 if (rv != PP_OK_COMPLETIONPENDING)
1542 callback.Run(rv); 1532 callback.Run(rv);
1543 } 1533 }
1544 1534
1545 pp::URLLoader OutOfProcessInstance::CreateURLLoaderInternal() { 1535 pp::URLLoader OutOfProcessInstance::CreateURLLoaderInternal() {
1546 pp::URLLoader loader(this); 1536 pp::URLLoader loader(this);
1547 1537
1548 const PPB_URLLoaderTrusted* trusted_interface = 1538 const PPB_URLLoaderTrusted* trusted_interface =
1549 reinterpret_cast<const PPB_URLLoaderTrusted*>( 1539 reinterpret_cast<const PPB_URLLoaderTrusted*>(
1550 pp::Module::Get()->GetBrowserInterface( 1540 pp::Module::Get()->GetBrowserInterface(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 preview_pages_info_.push(std::make_pair(url, dst_page_index)); 1584 preview_pages_info_.push(std::make_pair(url, dst_page_index));
1595 LoadAvailablePreviewPage(); 1585 LoadAvailablePreviewPage();
1596 } 1586 }
1597 1587
1598 void OutOfProcessInstance::LoadAvailablePreviewPage() { 1588 void OutOfProcessInstance::LoadAvailablePreviewPage() {
1599 if (preview_pages_info_.empty() || 1589 if (preview_pages_info_.empty() ||
1600 document_load_state_ != LOAD_STATE_COMPLETE) { 1590 document_load_state_ != LOAD_STATE_COMPLETE) {
1601 return; 1591 return;
1602 } 1592 }
1603 1593
1604 std::string url = preview_pages_info_.front().first; 1594 const std::string& url = preview_pages_info_.front().first;
1605 int dst_page_index = preview_pages_info_.front().second; 1595 int dst_page_index = preview_pages_info_.front().second;
1606 int src_page_index = ExtractPrintPreviewPageIndex(url); 1596 int src_page_index = ExtractPrintPreviewPageIndex(url);
1607 if (src_page_index < 1 || dst_page_index >= print_preview_page_count_ || 1597 if (src_page_index < 1 || dst_page_index >= print_preview_page_count_ ||
1608 preview_document_load_state_ == LOAD_STATE_LOADING) { 1598 preview_document_load_state_ == LOAD_STATE_LOADING) {
1609 return; 1599 return;
1610 } 1600 }
1611 1601
1612 preview_document_load_state_ = LOAD_STATE_LOADING; 1602 preview_document_load_state_ = LOAD_STATE_LOADING;
1613 LoadPreviewUrl(url); 1603 LoadUrl(url, true /* is_print_preview */);
1614 } 1604 }
1615 1605
1616 void OutOfProcessInstance::UserMetricsRecordAction(const std::string& action) { 1606 void OutOfProcessInstance::UserMetricsRecordAction(const std::string& action) {
1617 // TODO(raymes): Move this function to PPB_UMA_Private. 1607 // TODO(raymes): Move this function to PPB_UMA_Private.
1618 pp::PDF::UserMetricsRecordAction(this, pp::Var(action)); 1608 pp::PDF::UserMetricsRecordAction(this, pp::Var(action));
1619 } 1609 }
1620 1610
1621 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( 1611 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument(
1622 const pp::FloatPoint& scroll_offset) { 1612 const pp::FloatPoint& scroll_offset) {
1623 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1613 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1624 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); 1614 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
1625 float min_y = -top_toolbar_height_; 1615 float min_y = -top_toolbar_height_;
1626 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1616 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1627 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); 1617 float y = std::max(std::min(scroll_offset.y(), max_y), min_y);
1628 return pp::FloatPoint(x, y); 1618 return pp::FloatPoint(x, y);
1629 } 1619 }
1630 1620
1631 } // namespace chrome_pdf 1621 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/out_of_process_instance.h ('k') | pdf/pdf_engine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698