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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 last_active_time_(base::TimeTicks::Now()), | 331 last_active_time_(base::TimeTicks::Now()), |
332 closed_by_user_gesture_(false), | 332 closed_by_user_gesture_(false), |
333 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), | 333 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), |
334 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), | 334 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), |
335 temporary_zoom_settings_(false), | 335 temporary_zoom_settings_(false), |
336 totalPinchGestureAmount_(0), | 336 totalPinchGestureAmount_(0), |
337 currentPinchZoomStepDelta_(0), | 337 currentPinchZoomStepDelta_(0), |
338 color_chooser_identifier_(0), | 338 color_chooser_identifier_(0), |
339 render_view_message_source_(NULL), | 339 render_view_message_source_(NULL), |
340 fullscreen_widget_routing_id_(MSG_ROUTING_NONE), | 340 fullscreen_widget_routing_id_(MSG_ROUTING_NONE), |
341 is_subframe_(false) { | 341 is_subframe_(false), |
342 current_zoom_mode_(kZoomModeDefault), | |
343 current_zoom_id_(1) { | |
342 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) | 344 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
343 g_created_callbacks.Get().at(i).Run(this); | 345 g_created_callbacks.Get().at(i).Run(this); |
344 frame_tree_.SetFrameRemoveListener( | 346 frame_tree_.SetFrameRemoveListener( |
345 base::Bind(&WebContentsImpl::OnFrameRemoved, | 347 base::Bind(&WebContentsImpl::OnFrameRemoved, |
346 base::Unretained(this))); | 348 base::Unretained(this))); |
347 } | 349 } |
348 | 350 |
349 WebContentsImpl::~WebContentsImpl() { | 351 WebContentsImpl::~WebContentsImpl() { |
350 is_being_destroyed_ = true; | 352 is_being_destroyed_ = true; |
351 | 353 |
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1979 } | 1981 } |
1980 | 1982 |
1981 void WebContentsImpl::SetClosedByUserGesture(bool value) { | 1983 void WebContentsImpl::SetClosedByUserGesture(bool value) { |
1982 closed_by_user_gesture_ = value; | 1984 closed_by_user_gesture_ = value; |
1983 } | 1985 } |
1984 | 1986 |
1985 bool WebContentsImpl::GetClosedByUserGesture() const { | 1987 bool WebContentsImpl::GetClosedByUserGesture() const { |
1986 return closed_by_user_gesture_; | 1988 return closed_by_user_gesture_; |
1987 } | 1989 } |
1988 | 1990 |
1991 content::ZoomMode WebContentsImpl::GetZoomMode() const { | |
1992 return current_zoom_mode_; | |
1993 } | |
1994 | |
1989 double WebContentsImpl::GetZoomLevel() const { | 1995 double WebContentsImpl::GetZoomLevel() const { |
1996 if (current_zoom_mode_ == kZoomModeDisabled) | |
1997 return 0; | |
1998 | |
1990 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>( | 1999 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>( |
1991 HostZoomMap::GetForBrowserContext(GetBrowserContext())); | 2000 HostZoomMap::GetForBrowserContext(GetBrowserContext())); |
1992 if (!zoom_map) | 2001 if (!zoom_map) |
1993 return 0; | 2002 return 0; |
1994 | 2003 |
1995 double zoom_level; | 2004 double zoom_level; |
1996 if (temporary_zoom_settings_) { | 2005 if (temporary_zoom_settings_) { |
1997 zoom_level = zoom_map->GetTemporaryZoomLevel( | 2006 zoom_level = zoom_map->GetTemporaryZoomLevel( |
1998 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID()); | 2007 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID()); |
1999 } else { | 2008 } else { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2079 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size); | 2088 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size); |
2080 image_download_map_[id] = callback; | 2089 image_download_map_[id] = callback; |
2081 return id; | 2090 return id; |
2082 } | 2091 } |
2083 | 2092 |
2084 bool WebContentsImpl::IsSubframe() const { | 2093 bool WebContentsImpl::IsSubframe() const { |
2085 return is_subframe_; | 2094 return is_subframe_; |
2086 } | 2095 } |
2087 | 2096 |
2088 void WebContentsImpl::SetZoomLevel(double level) { | 2097 void WebContentsImpl::SetZoomLevel(double level) { |
2089 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level)); | 2098 if (current_zoom_mode_ == kZoomModeDisabled) |
2099 return; | |
2100 | |
2101 // Notify observers about the initiated zoom change. | |
2102 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | |
Fady Samuel
2014/04/10 17:09:03
Can this go at the bottom after all other operatio
paulmeyer
2014/04/10 17:24:37
Yes. Done.
| |
2103 DidSetZoomLevel(GetZoomLevel(), level, current_zoom_mode_)); | |
2104 | |
2105 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), current_zoom_id_++, level, | |
2106 current_zoom_mode_)); | |
2090 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder(); | 2107 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder(); |
2091 if (embedder) | 2108 if (embedder) |
2092 embedder->SetZoomLevel(level); | 2109 embedder->SetZoomLevel(level); |
2093 } | 2110 } |
2094 | 2111 |
2112 void WebContentsImpl::SetZoomLevel(double level, | |
2113 const base::Callback<void(void)>& callback) { | |
2114 if (current_zoom_mode_ == kZoomModeDisabled) | |
2115 return; | |
2116 | |
2117 // Add the callback to HostZoomMap so that it can be called after the zoom | |
2118 // change has completed. | |
2119 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>( | |
2120 HostZoomMap::GetForBrowserContext(GetBrowserContext())); | |
2121 DCHECK(zoom_map); | |
2122 zoom_map->AddZoomCallback(current_zoom_id_, callback); | |
2123 SetZoomLevel(level); | |
2124 } | |
2125 | |
2126 void WebContentsImpl::SetZoomMode(ZoomMode mode) { | |
2127 if (mode == current_zoom_mode_) | |
2128 return; | |
2129 | |
2130 double original_zoom_level = GetZoomLevel(); | |
2131 switch (mode) { | |
2132 case kZoomModeDefault: { | |
2133 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, original_zoom_level, | |
2134 kZoomModeDefault)); | |
2135 // Remove per-tab zoom data for this tab. | |
2136 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>( | |
2137 HostZoomMap::GetForBrowserContext(GetBrowserContext())); | |
2138 DCHECK(zoom_map); | |
2139 int render_process_id = GetRenderProcessHost()->GetID(); | |
2140 int render_view_id = GetRenderViewHost()->GetRoutingID(); | |
2141 zoom_map->EraseTemporaryZoomLevel(render_process_id, render_view_id); | |
2142 break; | |
2143 } | |
2144 case kZoomModeIsolated: { | |
2145 if (current_zoom_mode_ != kZoomModeDisabled) { | |
Fady Samuel
2014/04/10 17:09:03
Please explain in comments what this check does.
paulmeyer
2014/04/10 17:24:37
Done.
| |
2146 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, original_zoom_level, | |
2147 kZoomModeIsolated)); | |
2148 } | |
2149 break; | |
2150 } | |
2151 case kZoomModeManual: { | |
2152 if (current_zoom_mode_ != kZoomModeDisabled) { | |
Fady Samuel
2014/04/10 17:09:03
Please explain in comments what this check does.
paulmeyer
2014/04/10 17:24:37
Done.
| |
2153 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, 0, kZoomModeIsolated)); | |
2154 current_zoom_mode_ = mode; | |
2155 SetZoomLevel(original_zoom_level); | |
2156 } | |
2157 break; | |
2158 } | |
2159 case kZoomModeDisabled: { | |
2160 if (current_zoom_mode_ != kZoomModeManual) { | |
Fady Samuel
2014/04/10 17:09:03
Please explain in comments what this check does.
paulmeyer
2014/04/10 17:24:37
Done.
| |
2161 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, 0, kZoomModeIsolated)); | |
2162 } | |
2163 break; | |
2164 } | |
2165 } | |
2166 | |
2167 current_zoom_mode_ = mode; | |
2168 temporary_zoom_settings_ = mode != kZoomModeDefault; | |
2169 } | |
2170 | |
2095 void WebContentsImpl::Find(int request_id, | 2171 void WebContentsImpl::Find(int request_id, |
2096 const base::string16& search_text, | 2172 const base::string16& search_text, |
2097 const blink::WebFindOptions& options) { | 2173 const blink::WebFindOptions& options) { |
2098 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options)); | 2174 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options)); |
2099 } | 2175 } |
2100 | 2176 |
2101 void WebContentsImpl::StopFinding(StopFindAction action) { | 2177 void WebContentsImpl::StopFinding(StopFindAction action) { |
2102 Send(new ViewMsg_StopFinding(GetRoutingID(), action)); | 2178 Send(new ViewMsg_StopFinding(GetRoutingID(), action)); |
2103 } | 2179 } |
2104 | 2180 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2419 void WebContentsImpl::OnGoToEntryAtOffset(int offset) { | 2495 void WebContentsImpl::OnGoToEntryAtOffset(int offset) { |
2420 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) | 2496 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) |
2421 controller_.GoToOffset(offset); | 2497 controller_.GoToOffset(offset); |
2422 } | 2498 } |
2423 | 2499 |
2424 void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent, | 2500 void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent, |
2425 int maximum_percent, | 2501 int maximum_percent, |
2426 bool remember) { | 2502 bool remember) { |
2427 minimum_zoom_percent_ = minimum_percent; | 2503 minimum_zoom_percent_ = minimum_percent; |
2428 maximum_zoom_percent_ = maximum_percent; | 2504 maximum_zoom_percent_ = maximum_percent; |
2429 temporary_zoom_settings_ = !remember; | 2505 temporary_zoom_settings_ = !remember || |
2506 current_zoom_mode_ != kZoomModeDefault; | |
2430 } | 2507 } |
2431 | 2508 |
2432 void WebContentsImpl::OnEnumerateDirectory(int request_id, | 2509 void WebContentsImpl::OnEnumerateDirectory(int request_id, |
2433 const base::FilePath& path) { | 2510 const base::FilePath& path) { |
2434 if (!delegate_) | 2511 if (!delegate_) |
2435 return; | 2512 return; |
2436 | 2513 |
2437 ChildProcessSecurityPolicyImpl* policy = | 2514 ChildProcessSecurityPolicyImpl* policy = |
2438 ChildProcessSecurityPolicyImpl::GetInstance(); | 2515 ChildProcessSecurityPolicyImpl::GetInstance(); |
2439 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path)) | 2516 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path)) |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2819 | 2896 |
2820 notify_disconnection_ = false; | 2897 notify_disconnection_ = false; |
2821 NotificationService::current()->Notify( | 2898 NotificationService::current()->Notify( |
2822 NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 2899 NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
2823 Source<WebContents>(this), | 2900 Source<WebContents>(this), |
2824 NotificationService::NoDetails()); | 2901 NotificationService::NoDetails()); |
2825 } | 2902 } |
2826 | 2903 |
2827 void WebContentsImpl::NotifyNavigationEntryCommitted( | 2904 void WebContentsImpl::NotifyNavigationEntryCommitted( |
2828 const LoadCommittedDetails& load_details) { | 2905 const LoadCommittedDetails& load_details) { |
2906 // The zoom mode resets on navigation to a different page. | |
2907 if (load_details.is_navigation_to_different_page()) { | |
2908 temporary_zoom_settings_ = false; | |
2909 SetZoomMode(kZoomModeDefault); | |
2910 } | |
2911 | |
2829 FOR_EACH_OBSERVER( | 2912 FOR_EACH_OBSERVER( |
2830 WebContentsObserver, observers_, NavigationEntryCommitted(load_details)); | 2913 WebContentsObserver, observers_, NavigationEntryCommitted(load_details)); |
2831 } | 2914 } |
2832 | 2915 |
2833 bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host, | 2916 bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host, |
2834 const IPC::Message& message) { | 2917 const IPC::Message& message) { |
2835 return OnMessageReceived(NULL, render_frame_host, message); | 2918 return OnMessageReceived(NULL, render_frame_host, message); |
2836 } | 2919 } |
2837 | 2920 |
2838 const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const { | 2921 const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const { |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3693 | 3776 |
3694 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 3777 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
3695 if (!delegate_) | 3778 if (!delegate_) |
3696 return; | 3779 return; |
3697 const gfx::Size new_size = GetPreferredSize(); | 3780 const gfx::Size new_size = GetPreferredSize(); |
3698 if (new_size != old_size) | 3781 if (new_size != old_size) |
3699 delegate_->UpdatePreferredSize(this, new_size); | 3782 delegate_->UpdatePreferredSize(this, new_size); |
3700 } | 3783 } |
3701 | 3784 |
3702 } // namespace content | 3785 } // namespace content |
OLD | NEW |