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 ZoomChangeDetails zoom_change_details; | |
2102 zoom_change_details.old_zoom_level = GetZoomLevel(); | |
2103 zoom_change_details.new_zoom_level = level; | |
2104 zoom_change_details.zoom_mode = current_zoom_mode_; | |
2105 NotificationService::current()->Notify( | |
2106 content::NOTIFICATION_WEB_CONTENTS_ZOOM_CHANGE, | |
2107 Source<WebContents>(this), | |
2108 content::Details<ZoomChangeDetails>( | |
2109 &zoom_change_details)); | |
2110 | |
2111 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), current_zoom_id_++, level, | |
2112 current_zoom_mode_)); | |
2090 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder(); | 2113 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder(); |
2091 if (embedder) | 2114 if (embedder) |
2092 embedder->SetZoomLevel(level); | 2115 embedder->SetZoomLevel(level); |
2093 } | 2116 } |
2094 | 2117 |
2118 void WebContentsImpl::SetZoomLevel(double level, | |
2119 const base::Callback<void(void)>& callback) { | |
2120 if (current_zoom_mode_ == kZoomModeDisabled) | |
2121 return; | |
2122 | |
2123 // Add the callback to HostZoomMap so that it can be called after the zoom | |
2124 // change has completed. | |
2125 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>( | |
2126 HostZoomMap::GetForBrowserContext(GetBrowserContext())); | |
2127 DCHECK(zoom_map); | |
2128 zoom_map->AddZoomCallback(current_zoom_id_, callback); | |
2129 SetZoomLevel(level); | |
2130 } | |
2131 | |
2132 void WebContentsImpl::SetZoomMode(ZoomMode mode) { | |
2133 if (mode == current_zoom_mode_) | |
2134 return; | |
2135 | |
2136 double original_zoom_level = GetZoomLevel(); | |
2137 | |
2138 if (mode == kZoomModeDefault) { | |
Fady Samuel
2014/04/10 14:27:25
I think a switch statement would be easier to read
paulmeyer
2014/04/10 15:11:49
Done.
| |
2139 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, original_zoom_level, | |
2140 kZoomModeDefault)); | |
2141 NotificationService::current()->Notify( | |
2142 NOTIFICATION_WEB_CONTENTS_NO_TEMPORARY_ZOOM_LEVEL, | |
2143 Source<WebContents>(this), | |
2144 NotificationService::NoDetails()); | |
2145 } else if (mode == kZoomModeIsolated) { | |
2146 if (current_zoom_mode_ != kZoomModeDisabled) { | |
2147 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, original_zoom_level, | |
2148 kZoomModeIsolated)); | |
2149 } | |
2150 } else if (mode == kZoomModeManual) { | |
2151 if (current_zoom_mode_ != kZoomModeDisabled) { | |
2152 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, 0, kZoomModeIsolated)); | |
2153 current_zoom_mode_ = mode; | |
2154 SetZoomLevel(original_zoom_level); | |
2155 } | |
2156 } else if (mode == kZoomModeDisabled) { | |
2157 if (current_zoom_mode_ != kZoomModeManual) { | |
2158 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, 0, kZoomModeIsolated)); | |
2159 } | |
2160 } else { | |
2161 NOTREACHED(); | |
2162 } | |
2163 | |
2164 current_zoom_mode_ = mode; | |
2165 temporary_zoom_settings_ = mode != kZoomModeDefault; | |
2166 } | |
2167 | |
2095 void WebContentsImpl::Find(int request_id, | 2168 void WebContentsImpl::Find(int request_id, |
2096 const base::string16& search_text, | 2169 const base::string16& search_text, |
2097 const blink::WebFindOptions& options) { | 2170 const blink::WebFindOptions& options) { |
2098 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options)); | 2171 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options)); |
2099 } | 2172 } |
2100 | 2173 |
2101 void WebContentsImpl::StopFinding(StopFindAction action) { | 2174 void WebContentsImpl::StopFinding(StopFindAction action) { |
2102 Send(new ViewMsg_StopFinding(GetRoutingID(), action)); | 2175 Send(new ViewMsg_StopFinding(GetRoutingID(), action)); |
2103 } | 2176 } |
2104 | 2177 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2419 void WebContentsImpl::OnGoToEntryAtOffset(int offset) { | 2492 void WebContentsImpl::OnGoToEntryAtOffset(int offset) { |
2420 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) | 2493 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) |
2421 controller_.GoToOffset(offset); | 2494 controller_.GoToOffset(offset); |
2422 } | 2495 } |
2423 | 2496 |
2424 void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent, | 2497 void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent, |
2425 int maximum_percent, | 2498 int maximum_percent, |
2426 bool remember) { | 2499 bool remember) { |
2427 minimum_zoom_percent_ = minimum_percent; | 2500 minimum_zoom_percent_ = minimum_percent; |
2428 maximum_zoom_percent_ = maximum_percent; | 2501 maximum_zoom_percent_ = maximum_percent; |
2429 temporary_zoom_settings_ = !remember; | 2502 temporary_zoom_settings_ = !remember || |
2503 current_zoom_mode_ != kZoomModeDefault; | |
2430 } | 2504 } |
2431 | 2505 |
2432 void WebContentsImpl::OnEnumerateDirectory(int request_id, | 2506 void WebContentsImpl::OnEnumerateDirectory(int request_id, |
2433 const base::FilePath& path) { | 2507 const base::FilePath& path) { |
2434 if (!delegate_) | 2508 if (!delegate_) |
2435 return; | 2509 return; |
2436 | 2510 |
2437 ChildProcessSecurityPolicyImpl* policy = | 2511 ChildProcessSecurityPolicyImpl* policy = |
2438 ChildProcessSecurityPolicyImpl::GetInstance(); | 2512 ChildProcessSecurityPolicyImpl::GetInstance(); |
2439 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path)) | 2513 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path)) |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2819 | 2893 |
2820 notify_disconnection_ = false; | 2894 notify_disconnection_ = false; |
2821 NotificationService::current()->Notify( | 2895 NotificationService::current()->Notify( |
2822 NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 2896 NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
2823 Source<WebContents>(this), | 2897 Source<WebContents>(this), |
2824 NotificationService::NoDetails()); | 2898 NotificationService::NoDetails()); |
2825 } | 2899 } |
2826 | 2900 |
2827 void WebContentsImpl::NotifyNavigationEntryCommitted( | 2901 void WebContentsImpl::NotifyNavigationEntryCommitted( |
2828 const LoadCommittedDetails& load_details) { | 2902 const LoadCommittedDetails& load_details) { |
2903 if (load_details.is_navigation_to_different_page()) { | |
Fady Samuel
2014/04/10 14:27:25
A comment here would be useful.
paulmeyer
2014/04/10 15:11:49
Done.
| |
2904 temporary_zoom_settings_ = false; | |
2905 SetZoomMode(kZoomModeDefault); | |
2906 } | |
2907 | |
2829 FOR_EACH_OBSERVER( | 2908 FOR_EACH_OBSERVER( |
2830 WebContentsObserver, observers_, NavigationEntryCommitted(load_details)); | 2909 WebContentsObserver, observers_, NavigationEntryCommitted(load_details)); |
2831 } | 2910 } |
2832 | 2911 |
2833 bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host, | 2912 bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host, |
2834 const IPC::Message& message) { | 2913 const IPC::Message& message) { |
2835 return OnMessageReceived(NULL, render_frame_host, message); | 2914 return OnMessageReceived(NULL, render_frame_host, message); |
2836 } | 2915 } |
2837 | 2916 |
2838 const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const { | 2917 const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const { |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3693 | 3772 |
3694 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 3773 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
3695 if (!delegate_) | 3774 if (!delegate_) |
3696 return; | 3775 return; |
3697 const gfx::Size new_size = GetPreferredSize(); | 3776 const gfx::Size new_size = GetPreferredSize(); |
3698 if (new_size != old_size) | 3777 if (new_size != old_size) |
3699 delegate_->UpdatePreferredSize(this, new_size); | 3778 delegate_->UpdatePreferredSize(this, new_size); |
3700 } | 3779 } |
3701 | 3780 |
3702 } // namespace content | 3781 } // namespace content |
OLD | NEW |