Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: content/browser/web_contents/web_contents_impl.cc

Issue 224733018: Changes to content/ to facilitate new zoom extension API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), current_zoom_id_++, level,
2102 current_zoom_mode_));
2090 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder(); 2103 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2091 if (embedder) 2104 if (embedder)
2092 embedder->SetZoomLevel(level); 2105 embedder->SetZoomLevel(level);
2106
2107 // Notify observers about the initiated zoom change.
2108 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2109 DidSetZoomLevel(GetZoomLevel(), level, current_zoom_mode_));
2110 }
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 // Unless the zoom mode was |kZoomModeDisabled| before this call, the page
2146 // needs an initial isolated zoom back to the same level it was at in the
2147 // other mode.
2148 if (current_zoom_mode_ != kZoomModeDisabled) {
2149 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, original_zoom_level,
2150 kZoomModeIsolated));
2151 }
2152 break;
2153 }
2154 case kZoomModeManual: {
2155 // Unless the zoom mode was |kZoomModeDisabled| before this call, the page
2156 // needs to be resized to the default zoom before calling SetZoomLevel()
2157 // so that the page can be resized manually to the same zoom as before.
2158 if (current_zoom_mode_ != kZoomModeDisabled) {
2159 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, 0, kZoomModeIsolated));
2160 current_zoom_mode_ = mode;
2161 SetZoomLevel(original_zoom_level);
2162 }
2163 break;
2164 }
2165 case kZoomModeDisabled: {
2166 // The page needs to be zoomed back to default before disabling the zoom
2167 // (unless it was just in |kZoomModeManual| mode, in which case this is
2168 // already done).
2169 if (current_zoom_mode_ != kZoomModeManual) {
2170 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, 0, kZoomModeIsolated));
2171 }
2172 break;
2173 }
2174 }
2175
2176 current_zoom_mode_ = mode;
2177 temporary_zoom_settings_ = mode != kZoomModeDefault;
2093 } 2178 }
2094 2179
2095 void WebContentsImpl::Find(int request_id, 2180 void WebContentsImpl::Find(int request_id,
2096 const base::string16& search_text, 2181 const base::string16& search_text,
2097 const blink::WebFindOptions& options) { 2182 const blink::WebFindOptions& options) {
2098 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options)); 2183 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2099 } 2184 }
2100 2185
2101 void WebContentsImpl::StopFinding(StopFindAction action) { 2186 void WebContentsImpl::StopFinding(StopFindAction action) {
2102 Send(new ViewMsg_StopFinding(GetRoutingID(), action)); 2187 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
2419 void WebContentsImpl::OnGoToEntryAtOffset(int offset) { 2504 void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
2420 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) 2505 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2421 controller_.GoToOffset(offset); 2506 controller_.GoToOffset(offset);
2422 } 2507 }
2423 2508
2424 void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent, 2509 void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2425 int maximum_percent, 2510 int maximum_percent,
2426 bool remember) { 2511 bool remember) {
2427 minimum_zoom_percent_ = minimum_percent; 2512 minimum_zoom_percent_ = minimum_percent;
2428 maximum_zoom_percent_ = maximum_percent; 2513 maximum_zoom_percent_ = maximum_percent;
2429 temporary_zoom_settings_ = !remember; 2514 temporary_zoom_settings_ = !remember ||
2515 current_zoom_mode_ != kZoomModeDefault;
2430 } 2516 }
2431 2517
2432 void WebContentsImpl::OnEnumerateDirectory(int request_id, 2518 void WebContentsImpl::OnEnumerateDirectory(int request_id,
2433 const base::FilePath& path) { 2519 const base::FilePath& path) {
2434 if (!delegate_) 2520 if (!delegate_)
2435 return; 2521 return;
2436 2522
2437 ChildProcessSecurityPolicyImpl* policy = 2523 ChildProcessSecurityPolicyImpl* policy =
2438 ChildProcessSecurityPolicyImpl::GetInstance(); 2524 ChildProcessSecurityPolicyImpl::GetInstance();
2439 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path)) 2525 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
2819 2905
2820 notify_disconnection_ = false; 2906 notify_disconnection_ = false;
2821 NotificationService::current()->Notify( 2907 NotificationService::current()->Notify(
2822 NOTIFICATION_WEB_CONTENTS_DISCONNECTED, 2908 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2823 Source<WebContents>(this), 2909 Source<WebContents>(this),
2824 NotificationService::NoDetails()); 2910 NotificationService::NoDetails());
2825 } 2911 }
2826 2912
2827 void WebContentsImpl::NotifyNavigationEntryCommitted( 2913 void WebContentsImpl::NotifyNavigationEntryCommitted(
2828 const LoadCommittedDetails& load_details) { 2914 const LoadCommittedDetails& load_details) {
2915 // The zoom mode resets on navigation to a different page.
2916 if (load_details.is_navigation_to_different_page()) {
2917 temporary_zoom_settings_ = false;
2918 SetZoomMode(kZoomModeDefault);
2919 }
2920
2829 FOR_EACH_OBSERVER( 2921 FOR_EACH_OBSERVER(
2830 WebContentsObserver, observers_, NavigationEntryCommitted(load_details)); 2922 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2831 } 2923 }
2832 2924
2833 bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host, 2925 bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2834 const IPC::Message& message) { 2926 const IPC::Message& message) {
2835 return OnMessageReceived(NULL, render_frame_host, message); 2927 return OnMessageReceived(NULL, render_frame_host, message);
2836 } 2928 }
2837 2929
2838 const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const { 2930 const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after
3693 3785
3694 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { 3786 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3695 if (!delegate_) 3787 if (!delegate_)
3696 return; 3788 return;
3697 const gfx::Size new_size = GetPreferredSize(); 3789 const gfx::Size new_size = GetPreferredSize();
3698 if (new_size != old_size) 3790 if (new_size != old_size)
3699 delegate_->UpdatePreferredSize(this, new_size); 3791 delegate_->UpdatePreferredSize(this, new_size);
3700 } 3792 }
3701 3793
3702 } // namespace content 3794 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698