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_(0) { |
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2078 const ImageDownloadCallback& callback) { | 2087 const ImageDownloadCallback& callback) { |
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 int WebContentsImpl::SetZoomLevel(double level) { |
2089 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level)); | 2098 if (current_zoom_mode_ == kZoomModeDisabled) |
| 2099 return 0; |
| 2100 |
| 2101 ++current_zoom_id_; |
| 2102 |
| 2103 ZoomChangeDetails zoom_change_details; |
| 2104 zoom_change_details.old_zoom_level = GetZoomLevel(); |
| 2105 zoom_change_details.new_zoom_level = level; |
| 2106 zoom_change_details.zoom_mode = current_zoom_mode_; |
| 2107 NotificationService::current()->Notify( |
| 2108 content::NOTIFICATION_WEB_CONTENTS_ZOOM_CHANGE, |
| 2109 Source<WebContents>(this), |
| 2110 content::Details<ZoomChangeDetails>( |
| 2111 &zoom_change_details)); |
| 2112 |
| 2113 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), current_zoom_id_, level, |
| 2114 current_zoom_mode_)); |
2090 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder(); | 2115 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder(); |
2091 if (embedder) | 2116 if (embedder) |
2092 embedder->SetZoomLevel(level); | 2117 embedder->SetZoomLevel(level); |
| 2118 |
| 2119 return current_zoom_id_; |
| 2120 } |
| 2121 |
| 2122 void WebContentsImpl::SetZoomMode(ZoomMode mode) { |
| 2123 if (mode == current_zoom_mode_) |
| 2124 return; |
| 2125 |
| 2126 double original_zoom_level = GetZoomLevel(); |
| 2127 |
| 2128 if (mode == kZoomModeDefault) { |
| 2129 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, original_zoom_level, |
| 2130 kZoomModeDefault)); |
| 2131 NotificationService::current()->Notify( |
| 2132 NOTIFICATION_WEB_CONTENTS_NO_TEMPORARY_ZOOM_LEVEL, |
| 2133 Source<WebContents>(this), |
| 2134 NotificationService::NoDetails()); |
| 2135 } else if (mode == kZoomModeIsolated) { |
| 2136 if (current_zoom_mode_ != kZoomModeDisabled) { |
| 2137 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, original_zoom_level, |
| 2138 kZoomModeIsolated)); |
| 2139 } |
| 2140 } else if (mode == kZoomModeManual) { |
| 2141 if (current_zoom_mode_ != kZoomModeDisabled) { |
| 2142 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, 0, kZoomModeIsolated)); |
| 2143 current_zoom_mode_ = mode; |
| 2144 SetZoomLevel(original_zoom_level); |
| 2145 } |
| 2146 } else if (mode == kZoomModeDisabled) { |
| 2147 if (current_zoom_mode_ != kZoomModeManual) { |
| 2148 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), 0, 0, kZoomModeIsolated)); |
| 2149 } |
| 2150 } else { |
| 2151 NOTREACHED(); |
| 2152 } |
| 2153 |
| 2154 current_zoom_mode_ = mode; |
| 2155 temporary_zoom_settings_ = mode != kZoomModeDefault; |
2093 } | 2156 } |
2094 | 2157 |
2095 void WebContentsImpl::Find(int request_id, | 2158 void WebContentsImpl::Find(int request_id, |
2096 const base::string16& search_text, | 2159 const base::string16& search_text, |
2097 const blink::WebFindOptions& options) { | 2160 const blink::WebFindOptions& options) { |
2098 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options)); | 2161 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options)); |
2099 } | 2162 } |
2100 | 2163 |
2101 void WebContentsImpl::StopFinding(StopFindAction action) { | 2164 void WebContentsImpl::StopFinding(StopFindAction action) { |
2102 Send(new ViewMsg_StopFinding(GetRoutingID(), action)); | 2165 Send(new ViewMsg_StopFinding(GetRoutingID(), action)); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2419 void WebContentsImpl::OnGoToEntryAtOffset(int offset) { | 2482 void WebContentsImpl::OnGoToEntryAtOffset(int offset) { |
2420 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) | 2483 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) |
2421 controller_.GoToOffset(offset); | 2484 controller_.GoToOffset(offset); |
2422 } | 2485 } |
2423 | 2486 |
2424 void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent, | 2487 void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent, |
2425 int maximum_percent, | 2488 int maximum_percent, |
2426 bool remember) { | 2489 bool remember) { |
2427 minimum_zoom_percent_ = minimum_percent; | 2490 minimum_zoom_percent_ = minimum_percent; |
2428 maximum_zoom_percent_ = maximum_percent; | 2491 maximum_zoom_percent_ = maximum_percent; |
2429 temporary_zoom_settings_ = !remember; | 2492 temporary_zoom_settings_ = !remember || |
| 2493 current_zoom_mode_ != kZoomModeDefault; |
2430 } | 2494 } |
2431 | 2495 |
2432 void WebContentsImpl::OnEnumerateDirectory(int request_id, | 2496 void WebContentsImpl::OnEnumerateDirectory(int request_id, |
2433 const base::FilePath& path) { | 2497 const base::FilePath& path) { |
2434 if (!delegate_) | 2498 if (!delegate_) |
2435 return; | 2499 return; |
2436 | 2500 |
2437 ChildProcessSecurityPolicyImpl* policy = | 2501 ChildProcessSecurityPolicyImpl* policy = |
2438 ChildProcessSecurityPolicyImpl::GetInstance(); | 2502 ChildProcessSecurityPolicyImpl::GetInstance(); |
2439 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path)) | 2503 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path)) |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2819 | 2883 |
2820 notify_disconnection_ = false; | 2884 notify_disconnection_ = false; |
2821 NotificationService::current()->Notify( | 2885 NotificationService::current()->Notify( |
2822 NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 2886 NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
2823 Source<WebContents>(this), | 2887 Source<WebContents>(this), |
2824 NotificationService::NoDetails()); | 2888 NotificationService::NoDetails()); |
2825 } | 2889 } |
2826 | 2890 |
2827 void WebContentsImpl::NotifyNavigationEntryCommitted( | 2891 void WebContentsImpl::NotifyNavigationEntryCommitted( |
2828 const LoadCommittedDetails& load_details) { | 2892 const LoadCommittedDetails& load_details) { |
| 2893 if (load_details.is_navigation_to_different_page()) { |
| 2894 temporary_zoom_settings_ = false; |
| 2895 SetZoomMode(kZoomModeDefault); |
| 2896 } |
| 2897 |
2829 FOR_EACH_OBSERVER( | 2898 FOR_EACH_OBSERVER( |
2830 WebContentsObserver, observers_, NavigationEntryCommitted(load_details)); | 2899 WebContentsObserver, observers_, NavigationEntryCommitted(load_details)); |
2831 } | 2900 } |
2832 | 2901 |
2833 bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host, | 2902 bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host, |
2834 const IPC::Message& message) { | 2903 const IPC::Message& message) { |
2835 return OnMessageReceived(NULL, render_frame_host, message); | 2904 return OnMessageReceived(NULL, render_frame_host, message); |
2836 } | 2905 } |
2837 | 2906 |
2838 const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const { | 2907 const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const { |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3693 | 3762 |
3694 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 3763 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
3695 if (!delegate_) | 3764 if (!delegate_) |
3696 return; | 3765 return; |
3697 const gfx::Size new_size = GetPreferredSize(); | 3766 const gfx::Size new_size = GetPreferredSize(); |
3698 if (new_size != old_size) | 3767 if (new_size != old_size) |
3699 delegate_->UpdatePreferredSize(this, new_size); | 3768 delegate_->UpdatePreferredSize(this, new_size); |
3700 } | 3769 } |
3701 | 3770 |
3702 } // namespace content | 3771 } // namespace content |
OLD | NEW |