OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome_frame/chrome_frame_npapi.h" | 5 #include "chrome_frame/chrome_frame_npapi.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 onprivatemessage_handler_ = JavascriptToNPObject(onprivatemessage_arg); | 262 onprivatemessage_handler_ = JavascriptToNPObject(onprivatemessage_arg); |
263 | 263 |
264 if (chrome_extra_arguments_arg) | 264 if (chrome_extra_arguments_arg) |
265 extra_arguments = UTF8ToWide(chrome_extra_arguments_arg); | 265 extra_arguments = UTF8ToWide(chrome_extra_arguments_arg); |
266 | 266 |
267 if (chrome_profile_name_arg) | 267 if (chrome_profile_name_arg) |
268 profile_name = UTF8ToWide(chrome_profile_name_arg); | 268 profile_name = UTF8ToWide(chrome_profile_name_arg); |
269 | 269 |
270 if (chrome_network_arg_set) | 270 if (chrome_network_arg_set) |
271 automation_client_->set_use_chrome_network(chrome_network_arg); | 271 automation_client_->set_use_chrome_network(chrome_network_arg); |
| 272 } |
272 | 273 |
273 } | 274 // Setup Url fetcher. |
| 275 url_fetcher_.set_NPPInstance(instance_); |
| 276 url_fetcher_.set_frame_busting(!is_privileged_); |
| 277 automation_client_->SetUrlFetcher(&url_fetcher_); |
274 | 278 |
275 // TODO(joshia): Initialize navigation here and send proxy config as | 279 // TODO(joshia): Initialize navigation here and send proxy config as |
276 // part of LaunchSettings | 280 // part of LaunchSettings |
277 /* | 281 /* |
278 if (!src_.empty()) | 282 if (!src_.empty()) |
279 automation_client_->InitiateNavigation(src_, is_privileged_); | 283 automation_client_->InitiateNavigation(src_, is_privileged_); |
280 | 284 |
281 std::string proxy_settings; | 285 std::string proxy_settings; |
282 bool has_prefs = pref_service_->Initialize(instance_, | 286 bool has_prefs = pref_service_->Initialize(instance_, |
283 automation_client_.get()); | 287 automation_client_.get()); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 } | 431 } |
428 | 432 |
429 void ChromeFrameNPAPI::UrlNotify(const char* url, NPReason reason, | 433 void ChromeFrameNPAPI::UrlNotify(const char* url, NPReason reason, |
430 void* notify_data) { | 434 void* notify_data) { |
431 if (enabled_popups_) { | 435 if (enabled_popups_) { |
432 // We have opened the URL so tell the browser to restore popup settings | 436 // We have opened the URL so tell the browser to restore popup settings |
433 enabled_popups_ = false; | 437 enabled_popups_ = false; |
434 npapi::PopPopupsEnabledState(instance_); | 438 npapi::PopPopupsEnabledState(instance_); |
435 } | 439 } |
436 | 440 |
437 // It is now safe to release the additional reference on the request | 441 url_fetcher_.UrlNotify(url, reason, notify_data); |
438 NPAPIUrlRequest* request = RequestFromNotifyData(notify_data); | |
439 if (request) { | |
440 request->Stop(); | |
441 request->Release(); | |
442 } | |
443 } | 442 } |
444 | 443 |
445 void ChromeFrameNPAPI::OnAcceleratorPressed(int tab_handle, | 444 void ChromeFrameNPAPI::OnAcceleratorPressed(int tab_handle, |
446 const MSG& accel_message) { | 445 const MSG& accel_message) { |
447 DLOG(INFO) << __FUNCTION__ << " msg:" | 446 DLOG(INFO) << __FUNCTION__ << " msg:" |
448 << StringPrintf("0x%04X", accel_message.message) << " key:" | 447 << StringPrintf("0x%04X", accel_message.message) << " key:" |
449 << accel_message.wParam; | 448 << accel_message.wParam; |
450 | 449 |
451 // The host browser does call TranslateMessage on messages like WM_KEYDOWN | 450 // The host browser does call TranslateMessage on messages like WM_KEYDOWN |
452 // WM_KEYUP, etc, which will result in messages like WM_CHAR, WM_SYSCHAR, etc | 451 // WM_KEYUP, etc, which will result in messages like WM_CHAR, WM_SYSCHAR, etc |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 default: | 504 default: |
506 break; | 505 break; |
507 } | 506 } |
508 | 507 |
509 // Tell the browser to temporarily allow popups | 508 // Tell the browser to temporarily allow popups |
510 enabled_popups_ = true; | 509 enabled_popups_ = true; |
511 npapi::PushPopupsEnabledState(instance_, TRUE); | 510 npapi::PushPopupsEnabledState(instance_, TRUE); |
512 npapi::GetURLNotify(instance_, url.spec().c_str(), target.c_str(), NULL); | 511 npapi::GetURLNotify(instance_, url.spec().c_str(), target.c_str(), NULL); |
513 } | 512 } |
514 | 513 |
515 void ChromeFrameNPAPI::OnRequestStart(int tab_handle, int request_id, | |
516 const IPC::AutomationURLRequest& request) { | |
517 scoped_refptr<NPAPIUrlRequest> new_request(new NPAPIUrlRequest(instance_)); | |
518 DCHECK(new_request); | |
519 if (new_request->Initialize(automation_client_.get(), tab_handle, | |
520 request_id, request.url, request.method, | |
521 request.referrer, request.extra_request_headers, | |
522 request.upload_data.get(), !is_privileged_)) { | |
523 if (new_request->Start()) { | |
524 // Keep additional reference on request for NPSTREAM | |
525 // This will be released in NPP_UrlNotify | |
526 new_request->AddRef(); | |
527 } | |
528 } | |
529 } | |
530 | |
531 void ChromeFrameNPAPI::OnRequestRead(int tab_handle, int request_id, | |
532 int bytes_to_read) { | |
533 automation_client_->ReadRequest(request_id, bytes_to_read); | |
534 } | |
535 | |
536 void ChromeFrameNPAPI::OnRequestEnd(int tab_handle, int request_id, | |
537 const URLRequestStatus& status) { | |
538 automation_client_->RemoveRequest(request_id, true); | |
539 } | |
540 | |
541 void ChromeFrameNPAPI::OnSetCookieAsync(int tab_handle, const GURL& url, | 514 void ChromeFrameNPAPI::OnSetCookieAsync(int tab_handle, const GURL& url, |
542 const std::string& cookie) { | 515 const std::string& cookie) { |
543 // Use the newer NPAPI way if available | 516 // Use the newer NPAPI way if available |
544 if (npapi::VersionMinor() >= NPVERS_HAS_URL_AND_AUTH_INFO) { | 517 if (npapi::VersionMinor() >= NPVERS_HAS_URL_AND_AUTH_INFO) { |
545 npapi::SetValueForURL(instance_, NPNURLVCookie, url.spec().c_str(), | 518 npapi::SetValueForURL(instance_, NPNURLVCookie, url.spec().c_str(), |
546 cookie.c_str(), cookie.length()); | 519 cookie.c_str(), cookie.length()); |
547 } else if (url == GURL(document_url_)) { | 520 } else if (url == GURL(document_url_)) { |
548 std::string script = "javascript:document.cookie="; | 521 std::string script = "javascript:document.cookie="; |
549 script.append(cookie); | 522 script.append(cookie); |
550 script.append(1, ';'); | 523 script.append(1, ';'); |
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1430 if (err == NPERR_NO_ERROR && private_mode) { | 1403 if (err == NPERR_NO_ERROR && private_mode) { |
1431 incognito_mode = true; | 1404 incognito_mode = true; |
1432 } | 1405 } |
1433 } else { | 1406 } else { |
1434 DLOG(WARNING) << "Not checking for private mode in Opera"; | 1407 DLOG(WARNING) << "Not checking for private mode in Opera"; |
1435 } | 1408 } |
1436 | 1409 |
1437 return incognito_mode; | 1410 return incognito_mode; |
1438 } | 1411 } |
1439 | 1412 |
1440 NPAPIUrlRequest* ChromeFrameNPAPI::ValidateRequest( | |
1441 NPP instance, void* notify_data) { | |
1442 ChromeFrameNPAPI* plugin_instance = | |
1443 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance); | |
1444 if (plugin_instance) { | |
1445 return plugin_instance->RequestFromNotifyData(notify_data); | |
1446 } | |
1447 | |
1448 return NULL; | |
1449 } | |
1450 | |
1451 NPAPIUrlRequest* ChromeFrameNPAPI::RequestFromNotifyData( | |
1452 void* notify_data) const { | |
1453 NPAPIUrlRequest* request = reinterpret_cast<NPAPIUrlRequest*>(notify_data); | |
1454 DCHECK(request ? automation_client_->IsValidRequest(request) : 1); | |
1455 return request; | |
1456 } | |
1457 | |
1458 bool ChromeFrameNPAPI::HandleContextMenuCommand(UINT cmd, | 1413 bool ChromeFrameNPAPI::HandleContextMenuCommand(UINT cmd, |
1459 const IPC::ContextMenuParams& params) { | 1414 const IPC::ContextMenuParams& params) { |
1460 if (cmd == IDC_ABOUT_CHROME_FRAME) { | 1415 if (cmd == IDC_ABOUT_CHROME_FRAME) { |
1461 // TODO: implement "About Chrome Frame" | 1416 // TODO: implement "About Chrome Frame" |
1462 } | 1417 } |
1463 return false; | 1418 return false; |
1464 } | 1419 } |
| 1420 |
| 1421 bool ChromeFrameNPAPI::NewStream(NPMIMEType type, NPStream* stream, |
| 1422 NPBool seekable, uint16* stream_type) { |
| 1423 return url_fetcher_.NewStream(type, stream, seekable, stream_type); |
| 1424 } |
| 1425 |
| 1426 int32 ChromeFrameNPAPI::WriteReady(NPStream* stream) { |
| 1427 return url_fetcher_.WriteReady(stream); |
| 1428 } |
| 1429 |
| 1430 int32 ChromeFrameNPAPI::Write(NPStream* stream, int32 offset, int32 len, |
| 1431 void* buffer) { |
| 1432 return url_fetcher_.Write(stream, offset, len, buffer); |
| 1433 } |
| 1434 |
| 1435 NPError ChromeFrameNPAPI::DestroyStream(NPStream* stream, NPReason reason) { |
| 1436 return url_fetcher_.DestroyStream(stream, reason); |
| 1437 } |
OLD | NEW |