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