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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 capturer_count_(0), | 336 capturer_count_(0), |
337 should_normally_be_visible_(true), | 337 should_normally_be_visible_(true), |
338 is_being_destroyed_(false), | 338 is_being_destroyed_(false), |
339 notify_disconnection_(false), | 339 notify_disconnection_(false), |
340 dialog_manager_(NULL), | 340 dialog_manager_(NULL), |
341 is_showing_before_unload_dialog_(false), | 341 is_showing_before_unload_dialog_(false), |
342 last_active_time_(base::TimeTicks::Now()), | 342 last_active_time_(base::TimeTicks::Now()), |
343 closed_by_user_gesture_(false), | 343 closed_by_user_gesture_(false), |
344 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), | 344 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), |
345 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), | 345 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), |
346 temporary_zoom_settings_(false), | |
347 totalPinchGestureAmount_(0), | 346 totalPinchGestureAmount_(0), |
348 currentPinchZoomStepDelta_(0), | 347 currentPinchZoomStepDelta_(0), |
349 render_view_message_source_(NULL), | 348 render_view_message_source_(NULL), |
350 fullscreen_widget_routing_id_(MSG_ROUTING_NONE), | 349 fullscreen_widget_routing_id_(MSG_ROUTING_NONE), |
351 is_subframe_(false), | 350 is_subframe_(false), |
352 last_dialog_suppressed_(false) { | 351 last_dialog_suppressed_(false) { |
353 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) | 352 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
354 g_created_callbacks.Get().at(i).Run(this); | 353 g_created_callbacks.Get().at(i).Run(this); |
355 frame_tree_.SetFrameRemoveListener( | 354 frame_tree_.SetFrameRemoveListener( |
356 base::Bind(&WebContentsImpl::OnFrameRemoved, | 355 base::Bind(&WebContentsImpl::OnFrameRemoved, |
(...skipping 1798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2155 } | 2154 } |
2156 | 2155 |
2157 void WebContentsImpl::SetClosedByUserGesture(bool value) { | 2156 void WebContentsImpl::SetClosedByUserGesture(bool value) { |
2158 closed_by_user_gesture_ = value; | 2157 closed_by_user_gesture_ = value; |
2159 } | 2158 } |
2160 | 2159 |
2161 bool WebContentsImpl::GetClosedByUserGesture() const { | 2160 bool WebContentsImpl::GetClosedByUserGesture() const { |
2162 return closed_by_user_gesture_; | 2161 return closed_by_user_gesture_; |
2163 } | 2162 } |
2164 | 2163 |
2165 double WebContentsImpl::GetZoomLevel() const { | |
2166 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>( | |
2167 HostZoomMap::GetForBrowserContext(GetBrowserContext())); | |
2168 if (!zoom_map) | |
2169 return 0; | |
2170 | |
2171 double zoom_level; | |
2172 if (temporary_zoom_settings_) { | |
2173 zoom_level = zoom_map->GetTemporaryZoomLevel( | |
2174 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID()); | |
2175 } else { | |
2176 GURL url; | |
2177 NavigationEntry* entry = GetController().GetLastCommittedEntry(); | |
2178 // Since zoom map is updated using rewritten URL, use rewritten URL | |
2179 // to get the zoom level. | |
2180 url = entry ? entry->GetURL() : GURL::EmptyGURL(); | |
2181 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(), | |
2182 net::GetHostOrSpecFromURL(url)); | |
2183 } | |
2184 return zoom_level; | |
2185 } | |
2186 | |
2187 int WebContentsImpl::GetZoomPercent(bool* enable_increment, | 2164 int WebContentsImpl::GetZoomPercent(bool* enable_increment, |
2188 bool* enable_decrement) const { | 2165 bool* enable_decrement) const { |
2189 *enable_decrement = *enable_increment = false; | 2166 *enable_decrement = *enable_increment = false; |
2190 // Calculate the zoom percent from the factor. Round up to the nearest whole | 2167 // Calculate the zoom percent from the factor. Round up to the nearest whole |
2191 // number. | 2168 // number. |
2192 int percent = static_cast<int>( | 2169 int percent = static_cast<int>( |
2193 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5); | 2170 ZoomLevelToZoomFactor(HostZoomMap::GetZoomLevel(this)) * 100 + 0.5); |
2194 *enable_decrement = percent > minimum_zoom_percent_; | 2171 *enable_decrement = percent > minimum_zoom_percent_; |
2195 *enable_increment = percent < maximum_zoom_percent_; | 2172 *enable_increment = percent < maximum_zoom_percent_; |
2196 return percent; | 2173 return percent; |
2197 } | 2174 } |
2198 | 2175 |
2199 void WebContentsImpl::ViewSource() { | 2176 void WebContentsImpl::ViewSource() { |
2200 if (!delegate_) | 2177 if (!delegate_) |
2201 return; | 2178 return; |
2202 | 2179 |
2203 NavigationEntry* entry = GetController().GetLastCommittedEntry(); | 2180 NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2272 const ImageDownloadCallback& callback) { | 2249 const ImageDownloadCallback& callback) { |
2273 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size); | 2250 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size); |
2274 image_download_map_[id] = callback; | 2251 image_download_map_[id] = callback; |
2275 return id; | 2252 return id; |
2276 } | 2253 } |
2277 | 2254 |
2278 bool WebContentsImpl::IsSubframe() const { | 2255 bool WebContentsImpl::IsSubframe() const { |
2279 return is_subframe_; | 2256 return is_subframe_; |
2280 } | 2257 } |
2281 | 2258 |
2282 void WebContentsImpl::SetZoomLevel(double level) { | |
2283 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level)); | |
2284 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder(); | |
2285 if (embedder) | |
2286 embedder->SetZoomLevel(level); | |
2287 } | |
2288 | |
2289 void WebContentsImpl::Find(int request_id, | 2259 void WebContentsImpl::Find(int request_id, |
2290 const base::string16& search_text, | 2260 const base::string16& search_text, |
2291 const blink::WebFindOptions& options) { | 2261 const blink::WebFindOptions& options) { |
2292 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options)); | 2262 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options)); |
2293 } | 2263 } |
2294 | 2264 |
2295 void WebContentsImpl::StopFinding(StopFindAction action) { | 2265 void WebContentsImpl::StopFinding(StopFindAction action) { |
2296 Send(new ViewMsg_StopFinding(GetRoutingID(), action)); | 2266 Send(new ViewMsg_StopFinding(GetRoutingID(), action)); |
2297 } | 2267 } |
2298 | 2268 |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2708 loading_weak_factory_.GetWeakPtr()), | 2678 loading_weak_factory_.GetWeakPtr()), |
2709 min_delay); | 2679 min_delay); |
2710 } | 2680 } |
2711 | 2681 |
2712 void WebContentsImpl::OnGoToEntryAtOffset(int offset) { | 2682 void WebContentsImpl::OnGoToEntryAtOffset(int offset) { |
2713 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) | 2683 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) |
2714 controller_.GoToOffset(offset); | 2684 controller_.GoToOffset(offset); |
2715 } | 2685 } |
2716 | 2686 |
2717 void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent, | 2687 void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent, |
2718 int maximum_percent, | 2688 int maximum_percent) { |
2719 bool remember) { | |
2720 minimum_zoom_percent_ = minimum_percent; | 2689 minimum_zoom_percent_ = minimum_percent; |
2721 maximum_zoom_percent_ = maximum_percent; | 2690 maximum_zoom_percent_ = maximum_percent; |
2722 temporary_zoom_settings_ = !remember; | |
2723 } | 2691 } |
2724 | 2692 |
2725 void WebContentsImpl::OnEnumerateDirectory(int request_id, | 2693 void WebContentsImpl::OnEnumerateDirectory(int request_id, |
2726 const base::FilePath& path) { | 2694 const base::FilePath& path) { |
2727 if (!delegate_) | 2695 if (!delegate_) |
2728 return; | 2696 return; |
2729 | 2697 |
2730 ChildProcessSecurityPolicyImpl* policy = | 2698 ChildProcessSecurityPolicyImpl* policy = |
2731 ChildProcessSecurityPolicyImpl::GetInstance(); | 2699 ChildProcessSecurityPolicyImpl::GetInstance(); |
2732 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path)) | 2700 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path)) |
(...skipping 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4088 | 4056 |
4089 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 4057 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
4090 if (!delegate_) | 4058 if (!delegate_) |
4091 return; | 4059 return; |
4092 const gfx::Size new_size = GetPreferredSize(); | 4060 const gfx::Size new_size = GetPreferredSize(); |
4093 if (new_size != old_size) | 4061 if (new_size != old_size) |
4094 delegate_->UpdatePreferredSize(this, new_size); | 4062 delegate_->UpdatePreferredSize(this, new_size); |
4095 } | 4063 } |
4096 | 4064 |
4097 } // namespace content | 4065 } // namespace content |
OLD | NEW |