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 "content/browser/browser_plugin/browser_plugin_guest.h" | 5 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 10 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
11 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" | 11 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" |
12 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 12 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
13 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
14 #include "content/browser/renderer_host/render_widget_host_impl.h" | 14 #include "content/browser/renderer_host/render_widget_host_impl.h" |
15 #include "content/browser/web_contents/web_contents_impl.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
16 #include "content/common/browser_plugin_messages.h" | 16 #include "content/common/browser_plugin_messages.h" |
17 #include "content/common/view_messages.h" | 17 #include "content/common/view_messages.h" |
18 #include "content/port/browser/render_view_host_delegate_view.h" | 18 #include "content/port/browser/render_view_host_delegate_view.h" |
| 19 #include "content/public/browser/navigation_entry.h" |
19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/notification_types.h" | 21 #include "content/public/browser/notification_types.h" |
21 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
22 #include "content/public/browser/render_widget_host_view.h" | 23 #include "content/public/browser/render_widget_host_view.h" |
23 #include "content/public/browser/resource_request_details.h" | 24 #include "content/public/browser/resource_request_details.h" |
24 #include "content/public/browser/user_metrics.h" | 25 #include "content/public/browser/user_metrics.h" |
25 #include "content/public/common/result_codes.h" | 26 #include "content/public/common/result_codes.h" |
26 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 27 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
27 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
(...skipping 27 matching lines...) Expand all Loading... |
56 base::TimeDelta::FromMilliseconds(kGuestHangTimeoutMs)), | 57 base::TimeDelta::FromMilliseconds(kGuestHangTimeoutMs)), |
57 focused_(focused), | 58 focused_(focused), |
58 visible_(visible) { | 59 visible_(visible) { |
59 DCHECK(web_contents); | 60 DCHECK(web_contents); |
60 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. | 61 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. |
61 new BrowserPluginGuestHelper(this, render_view_host); | 62 new BrowserPluginGuestHelper(this, render_view_host); |
62 | 63 |
63 notification_registrar_.Add( | 64 notification_registrar_.Add( |
64 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 65 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
65 content::Source<content::WebContents>(web_contents)); | 66 content::Source<content::WebContents>(web_contents)); |
| 67 notification_registrar_.Add( |
| 68 this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
| 69 content::Source<content::WebContents>(web_contents)); |
66 } | 70 } |
67 | 71 |
68 BrowserPluginGuest::~BrowserPluginGuest() { | 72 BrowserPluginGuest::~BrowserPluginGuest() { |
69 } | 73 } |
70 | 74 |
71 // static | 75 // static |
72 BrowserPluginGuest* BrowserPluginGuest::Create( | 76 BrowserPluginGuest* BrowserPluginGuest::Create( |
73 int instance_id, | 77 int instance_id, |
74 WebContentsImpl* web_contents, | 78 WebContentsImpl* web_contents, |
75 content::RenderViewHost* render_view_host, | 79 content::RenderViewHost* render_view_host, |
(...skipping 19 matching lines...) Expand all Loading... |
95 DCHECK_EQ(Source<WebContents>(source).ptr(), web_contents()); | 99 DCHECK_EQ(Source<WebContents>(source).ptr(), web_contents()); |
96 ResourceRedirectDetails* resource_redirect_details = | 100 ResourceRedirectDetails* resource_redirect_details = |
97 Details<ResourceRedirectDetails>(details).ptr(); | 101 Details<ResourceRedirectDetails>(details).ptr(); |
98 bool is_top_level = | 102 bool is_top_level = |
99 resource_redirect_details->resource_type == ResourceType::MAIN_FRAME; | 103 resource_redirect_details->resource_type == ResourceType::MAIN_FRAME; |
100 LoadRedirect(resource_redirect_details->url, | 104 LoadRedirect(resource_redirect_details->url, |
101 resource_redirect_details->new_url, | 105 resource_redirect_details->new_url, |
102 is_top_level); | 106 is_top_level); |
103 break; | 107 break; |
104 } | 108 } |
| 109 case NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED: { |
| 110 DCHECK_EQ(Source<WebContents>(source).ptr(), web_contents()); |
| 111 std::pair<NavigationEntry*, bool>* title = |
| 112 Details<std::pair<NavigationEntry*, bool> >(details).ptr(); |
| 113 if (title->first) { |
| 114 string16 title_text = title->first->GetTitle(); |
| 115 TitleChange(title_text); |
| 116 } |
| 117 break; |
| 118 } |
105 default: | 119 default: |
106 NOTREACHED() << "Unexpected notification sent."; | 120 NOTREACHED() << "Unexpected notification sent."; |
107 break; | 121 break; |
108 } | 122 } |
109 } | 123 } |
110 | 124 |
111 bool BrowserPluginGuest::ViewTakeFocus(bool reverse) { | 125 bool BrowserPluginGuest::ViewTakeFocus(bool reverse) { |
112 SendMessageToEmbedder( | 126 SendMessageToEmbedder( |
113 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); | 127 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); |
114 return true; | 128 return true; |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 | 444 |
431 void BrowserPluginGuest::LoadRedirect( | 445 void BrowserPluginGuest::LoadRedirect( |
432 const GURL& old_url, | 446 const GURL& old_url, |
433 const GURL& new_url, | 447 const GURL& new_url, |
434 bool is_top_level) { | 448 bool is_top_level) { |
435 SendMessageToEmbedder( | 449 SendMessageToEmbedder( |
436 new BrowserPluginMsg_LoadRedirect( | 450 new BrowserPluginMsg_LoadRedirect( |
437 instance_id(), old_url, new_url, is_top_level)); | 451 instance_id(), old_url, new_url, is_top_level)); |
438 } | 452 } |
439 | 453 |
| 454 void BrowserPluginGuest::TitleChange(const string16& title) { |
| 455 SendMessageToEmbedder( |
| 456 new BrowserPluginMsg_TitleChange(instance_id(), title)); |
| 457 } |
| 458 |
440 void BrowserPluginGuest::DidCommitProvisionalLoadForFrame( | 459 void BrowserPluginGuest::DidCommitProvisionalLoadForFrame( |
441 int64 frame_id, | 460 int64 frame_id, |
442 bool is_main_frame, | 461 bool is_main_frame, |
443 const GURL& url, | 462 const GURL& url, |
444 PageTransition transition_type, | 463 PageTransition transition_type, |
445 RenderViewHost* render_view_host) { | 464 RenderViewHost* render_view_host) { |
446 // Inform its embedder of the updated URL. | 465 // Inform its embedder of the updated URL. |
447 BrowserPluginMsg_LoadCommit_Params params; | 466 BrowserPluginMsg_LoadCommit_Params params; |
448 params.url = url; | 467 params.url = url; |
449 params.is_top_level = is_main_frame; | 468 params.is_top_level = is_main_frame; |
450 params.process_id = render_view_host->GetProcess()->GetID(); | 469 params.process_id = render_view_host->GetProcess()->GetID(); |
451 params.current_entry_index = | 470 params.current_entry_index = |
452 web_contents()->GetController().GetCurrentEntryIndex(); | 471 web_contents()->GetController().GetCurrentEntryIndex(); |
453 params.entry_count = | 472 params.entry_count = |
454 web_contents()->GetController().GetEntryCount(); | 473 web_contents()->GetController().GetEntryCount(); |
455 SendMessageToEmbedder( | 474 SendMessageToEmbedder( |
456 new BrowserPluginMsg_LoadCommit(instance_id(), params)); | 475 new BrowserPluginMsg_LoadCommit(instance_id(), params)); |
457 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); | 476 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); |
| 477 |
| 478 // Also update title on commit, since the notifications only occur for |
| 479 // changes to existing titles, not updates due to back/forward or to |
| 480 // new pages with no titles. |
| 481 TitleChange(web_contents()->GetTitle()); |
458 } | 482 } |
459 | 483 |
460 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { | 484 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { |
461 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(instance_id())); | 485 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(instance_id())); |
462 } | 486 } |
463 | 487 |
464 void BrowserPluginGuest::RenderViewReady() { | 488 void BrowserPluginGuest::RenderViewReady() { |
465 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 489 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
466 // here (see http://www.crbug.com/158151). | 490 // here (see http://www.crbug.com/158151). |
467 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost(); | 491 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 default: | 527 default: |
504 break; | 528 break; |
505 } | 529 } |
506 } | 530 } |
507 | 531 |
508 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { | 532 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { |
509 embedder_web_contents_->GetRenderProcessHost()->Send(msg); | 533 embedder_web_contents_->GetRenderProcessHost()->Send(msg); |
510 } | 534 } |
511 | 535 |
512 } // namespace content | 536 } // namespace content |
OLD | NEW |