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/web_contents/web_contents_impl.h" | 5 #include "content/browser/web_contents/web_contents_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 | 860 |
861 std::set<GURL> WebContentsImpl::GetSitesInTab() const { | 861 std::set<GURL> WebContentsImpl::GetSitesInTab() const { |
862 std::set<GURL> sites; | 862 std::set<GURL> sites; |
863 frame_tree_.ForEach(base::Bind(&CollectSites, | 863 frame_tree_.ForEach(base::Bind(&CollectSites, |
864 base::Unretained(GetBrowserContext()), | 864 base::Unretained(GetBrowserContext()), |
865 base::Unretained(&sites))); | 865 base::Unretained(&sites))); |
866 return sites; | 866 return sites; |
867 } | 867 } |
868 | 868 |
869 const std::string& WebContentsImpl::GetEncoding() const { | 869 const std::string& WebContentsImpl::GetEncoding() const { |
870 return encoding_; | 870 return canonical_encoding_; |
871 } | 871 } |
872 | 872 |
873 bool WebContentsImpl::DisplayedInsecureContent() const { | 873 bool WebContentsImpl::DisplayedInsecureContent() const { |
874 return displayed_insecure_content_; | 874 return displayed_insecure_content_; |
875 } | 875 } |
876 | 876 |
877 void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) { | 877 void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) { |
878 DCHECK(!is_being_destroyed_); | 878 DCHECK(!is_being_destroyed_); |
879 ++capturer_count_; | 879 ++capturer_count_; |
880 DVLOG(1) << "There are now " << capturer_count_ | 880 DVLOG(1) << "There are now " << capturer_count_ |
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2079 bool WebContentsImpl::WillNotifyDisconnection() const { | 2079 bool WebContentsImpl::WillNotifyDisconnection() const { |
2080 return notify_disconnection_; | 2080 return notify_disconnection_; |
2081 } | 2081 } |
2082 | 2082 |
2083 void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) { | 2083 void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) { |
2084 SetEncoding(encoding); | 2084 SetEncoding(encoding); |
2085 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding)); | 2085 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding)); |
2086 } | 2086 } |
2087 | 2087 |
2088 void WebContentsImpl::ResetOverrideEncoding() { | 2088 void WebContentsImpl::ResetOverrideEncoding() { |
2089 encoding_.clear(); | 2089 canonical_encoding_.clear(); |
2090 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID())); | 2090 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID())); |
2091 } | 2091 } |
2092 | 2092 |
2093 RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() { | 2093 RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() { |
2094 return &renderer_preferences_; | 2094 return &renderer_preferences_; |
2095 } | 2095 } |
2096 | 2096 |
2097 void WebContentsImpl::Close() { | 2097 void WebContentsImpl::Close() { |
2098 Close(GetRenderViewHost()); | 2098 Close(GetRenderViewHost()); |
2099 } | 2099 } |
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3324 if (entry_index < 0) | 3324 if (entry_index < 0) |
3325 return; | 3325 return; |
3326 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index); | 3326 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index); |
3327 | 3327 |
3328 if (page_state == entry->GetPageState()) | 3328 if (page_state == entry->GetPageState()) |
3329 return; // Nothing to update. | 3329 return; // Nothing to update. |
3330 entry->SetPageState(page_state); | 3330 entry->SetPageState(page_state); |
3331 controller_.NotifyEntryChanged(entry, entry_index); | 3331 controller_.NotifyEntryChanged(entry, entry_index); |
3332 } | 3332 } |
3333 | 3333 |
3334 void WebContentsImpl::UpdateTitle(RenderViewHost* rvh, | |
3335 int32 page_id, | |
3336 const base::string16& title, | |
3337 base::i18n::TextDirection title_direction) { | |
3338 // If we have a title, that's a pretty good indication that we've started | |
3339 // getting useful data. | |
3340 SetNotWaitingForResponse(); | |
3341 | |
3342 // Try to find the navigation entry, which might not be the current one. | |
3343 // For example, it might be from a pending RVH for the pending entry. | |
3344 NavigationEntryImpl* entry = controller_.GetEntryWithPageID( | |
3345 rvh->GetSiteInstance(), page_id); | |
3346 | |
3347 // We can handle title updates when we don't have an entry in | |
3348 // UpdateTitleForEntry, but only if the update is from the current RVH. | |
3349 if (!entry && rvh != GetRenderViewHost()) | |
3350 return; | |
3351 | |
3352 // TODO(evan): make use of title_direction. | |
3353 // http://code.google.com/p/chromium/issues/detail?id=27094 | |
3354 if (!UpdateTitleForEntry(entry, title)) | |
3355 return; | |
3356 | |
3357 // Broadcast notifications when the UI should be updated. | |
3358 if (entry == controller_.GetEntryAtOffset(0)) | |
3359 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE); | |
3360 } | |
3361 | |
3362 void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host, | |
3363 const std::string& encoding) { | |
3364 SetEncoding(encoding); | |
3365 } | |
3366 | |
3367 void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) { | 3334 void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) { |
3368 if (delegate_) | 3335 if (delegate_) |
3369 delegate_->UpdateTargetURL(this, page_id, url); | 3336 delegate_->UpdateTargetURL(this, page_id, url); |
3370 } | 3337 } |
3371 | 3338 |
3372 void WebContentsImpl::Close(RenderViewHost* rvh) { | 3339 void WebContentsImpl::Close(RenderViewHost* rvh) { |
3373 #if defined(OS_MACOSX) | 3340 #if defined(OS_MACOSX) |
3374 // The UI may be in an event-tracking loop, such as between the | 3341 // The UI may be in an event-tracking loop, such as between the |
3375 // mouse-down and mouse-up in text selection or a button click. | 3342 // mouse-down and mouse-up in text selection or a button click. |
3376 // Defer the close until after tracking is complete, so that we | 3343 // Defer the close until after tracking is complete, so that we |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3475 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3442 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
3476 DocumentOnLoadCompletedInMainFrame()); | 3443 DocumentOnLoadCompletedInMainFrame()); |
3477 | 3444 |
3478 // TODO(avi): Remove. http://crbug.com/170921 | 3445 // TODO(avi): Remove. http://crbug.com/170921 |
3479 NotificationService::current()->Notify( | 3446 NotificationService::current()->Notify( |
3480 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 3447 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
3481 Source<WebContents>(this), | 3448 Source<WebContents>(this), |
3482 NotificationService::NoDetails()); | 3449 NotificationService::NoDetails()); |
3483 } | 3450 } |
3484 | 3451 |
| 3452 void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host, |
| 3453 int32 page_id, |
| 3454 const base::string16& title, |
| 3455 base::i18n::TextDirection title_direction) { |
| 3456 RenderViewHost* rvh = render_frame_host->GetRenderViewHost(); |
| 3457 |
| 3458 // If we have a title, that's a pretty good indication that we've started |
| 3459 // getting useful data. |
| 3460 SetNotWaitingForResponse(); |
| 3461 |
| 3462 // Try to find the navigation entry, which might not be the current one. |
| 3463 // For example, it might be from a pending RVH for the pending entry. |
| 3464 NavigationEntryImpl* entry = controller_.GetEntryWithPageID( |
| 3465 rvh->GetSiteInstance(), page_id); |
| 3466 |
| 3467 // We can handle title updates when we don't have an entry in |
| 3468 // UpdateTitleForEntry, but only if the update is from the current RVH. |
| 3469 // TODO(avi): Change to make decisions based on the RenderFrameHost. |
| 3470 if (!entry && rvh != GetRenderViewHost()) |
| 3471 return; |
| 3472 |
| 3473 // TODO(evan): make use of title_direction. |
| 3474 // http://code.google.com/p/chromium/issues/detail?id=27094 |
| 3475 if (!UpdateTitleForEntry(entry, title)) |
| 3476 return; |
| 3477 |
| 3478 // Broadcast notifications when the UI should be updated. |
| 3479 if (entry == controller_.GetEntryAtOffset(0)) |
| 3480 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE); |
| 3481 } |
| 3482 |
| 3483 void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host, |
| 3484 const std::string& encoding) { |
| 3485 SetEncoding(encoding); |
| 3486 } |
| 3487 |
3485 void WebContentsImpl::DocumentAvailableInMainFrame( | 3488 void WebContentsImpl::DocumentAvailableInMainFrame( |
3486 RenderViewHost* render_view_host) { | 3489 RenderViewHost* render_view_host) { |
3487 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3490 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
3488 DocumentAvailableInMainFrame()); | 3491 DocumentAvailableInMainFrame()); |
3489 } | 3492 } |
3490 void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) { | 3493 void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) { |
3491 // Tell the active RenderViewHost to run unload handlers and close, as long | 3494 // Tell the active RenderViewHost to run unload handlers and close, as long |
3492 // as the request came from a RenderViewHost in the same BrowsingInstance. | 3495 // as the request came from a RenderViewHost in the same BrowsingInstance. |
3493 // In most cases, we receive this from a swapped out RenderViewHost. | 3496 // In most cases, we receive this from a swapped out RenderViewHost. |
3494 // It is possible to receive it from one that has just been swapped in, | 3497 // It is possible to receive it from one that has just been swapped in, |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3881 if (rfh) { | 3884 if (rfh) { |
3882 rfh->JavaScriptDialogClosed(reply_msg, success, user_input, | 3885 rfh->JavaScriptDialogClosed(reply_msg, success, user_input, |
3883 dialog_was_suppressed); | 3886 dialog_was_suppressed); |
3884 } else { | 3887 } else { |
3885 // Don't leak the sync IPC reply if the RFH or process is gone. | 3888 // Don't leak the sync IPC reply if the RFH or process is gone. |
3886 delete reply_msg; | 3889 delete reply_msg; |
3887 } | 3890 } |
3888 } | 3891 } |
3889 | 3892 |
3890 void WebContentsImpl::SetEncoding(const std::string& encoding) { | 3893 void WebContentsImpl::SetEncoding(const std::string& encoding) { |
3891 encoding_ = GetContentClient()->browser()-> | 3894 if (encoding == last_reported_encoding_) |
| 3895 return; |
| 3896 last_reported_encoding_ = encoding; |
| 3897 |
| 3898 canonical_encoding_ = GetContentClient()->browser()-> |
3892 GetCanonicalEncodingNameByAliasName(encoding); | 3899 GetCanonicalEncodingNameByAliasName(encoding); |
3893 } | 3900 } |
3894 | 3901 |
3895 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 3902 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
3896 RenderWidgetHostViewBase* rwh_view = view_->CreateViewForWidget(rvh); | 3903 RenderWidgetHostViewBase* rwh_view = view_->CreateViewForWidget(rvh); |
3897 // Can be NULL during tests. | 3904 // Can be NULL during tests. |
3898 if (rwh_view) | 3905 if (rwh_view) |
3899 rwh_view->SetSize(GetContainerBounds().size()); | 3906 rwh_view->SetSize(GetContainerBounds().size()); |
3900 } | 3907 } |
3901 | 3908 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3955 | 3962 |
3956 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 3963 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
3957 if (!delegate_) | 3964 if (!delegate_) |
3958 return; | 3965 return; |
3959 const gfx::Size new_size = GetPreferredSize(); | 3966 const gfx::Size new_size = GetPreferredSize(); |
3960 if (new_size != old_size) | 3967 if (new_size != old_size) |
3961 delegate_->UpdatePreferredSize(this, new_size); | 3968 delegate_->UpdatePreferredSize(this, new_size); |
3962 } | 3969 } |
3963 | 3970 |
3964 } // namespace content | 3971 } // namespace content |
OLD | NEW |