Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/renderer_context_menu/render_view_context_menu_base.h" | 5 #include "components/renderer_context_menu/render_view_context_menu_base.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "content/public/browser/render_frame_host.h" | 12 #include "content/public/browser/render_frame_host.h" |
| 13 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
| 14 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
| 15 #include "content/public/browser/render_widget_host_view.h" | 15 #include "content/public/browser/render_widget_host_view.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/common/menu_item.h" | 17 #include "content/public/common/menu_item.h" |
| 18 #if defined(ENABLE_EXTENSIONS) | |
| 19 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues t.h" | |
| 20 #endif | |
| 18 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 21 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
| 19 | 22 |
| 20 using blink::WebContextMenuData; | 23 using blink::WebContextMenuData; |
| 21 using blink::WebString; | 24 using blink::WebString; |
| 22 using blink::WebURL; | 25 using blink::WebURL; |
| 23 using content::BrowserContext; | 26 using content::BrowserContext; |
| 24 using content::OpenURLParams; | 27 using content::OpenURLParams; |
| 25 using content::RenderFrameHost; | 28 using content::RenderFrameHost; |
| 26 using content::RenderViewHost; | 29 using content::RenderViewHost; |
| 27 using content::WebContents; | 30 using content::WebContents; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 submenu); | 122 submenu); |
| 120 break; | 123 break; |
| 121 } | 124 } |
| 122 default: | 125 default: |
| 123 NOTREACHED(); | 126 NOTREACHED(); |
| 124 break; | 127 break; |
| 125 } | 128 } |
| 126 } | 129 } |
| 127 } | 130 } |
| 128 | 131 |
| 132 content::WebContents* GetWebContentsToUse(content::WebContents* web_contents) { | |
| 133 // If we're viewing the PDF in a MimeHandlerViewGuest, use its embedder | |
|
raymes
2015/02/11 00:45:39
Please don't mention PDF here, just mention MimeHa
Deepak
2015/02/11 05:27:01
Done.
| |
| 134 // WebContents. | |
| 135 #if defined(ENABLE_EXTENSIONS) | |
| 136 auto guest_view = | |
| 137 extensions::MimeHandlerViewGuest::FromWebContents(web_contents); | |
| 138 if (guest_view) | |
| 139 return guest_view->embedder_web_contents(); | |
| 140 #endif | |
| 141 return web_contents; | |
| 142 } | |
| 143 | |
| 129 } // namespace | 144 } // namespace |
| 130 | 145 |
| 131 // static | 146 // static |
| 132 void RenderViewContextMenuBase::SetContentCustomCommandIdRange( | 147 void RenderViewContextMenuBase::SetContentCustomCommandIdRange( |
| 133 int first, int last) { | 148 int first, int last) { |
| 134 // The range is inclusive. | 149 // The range is inclusive. |
| 135 content_context_custom_first = first; | 150 content_context_custom_first = first; |
| 136 content_context_custom_last = last; | 151 content_context_custom_last = last; |
| 137 } | 152 } |
| 138 | 153 |
| 139 // static | 154 // static |
| 140 const size_t RenderViewContextMenuBase::kMaxSelectionTextLength = 50; | 155 const size_t RenderViewContextMenuBase::kMaxSelectionTextLength = 50; |
| 141 | 156 |
| 142 // static | 157 // static |
| 143 int RenderViewContextMenuBase::ConvertToContentCustomCommandId(int id) { | 158 int RenderViewContextMenuBase::ConvertToContentCustomCommandId(int id) { |
| 144 return content_context_custom_first + id; | 159 return content_context_custom_first + id; |
| 145 } | 160 } |
| 146 | 161 |
| 147 // static | 162 // static |
| 148 bool RenderViewContextMenuBase::IsContentCustomCommandId(int id) { | 163 bool RenderViewContextMenuBase::IsContentCustomCommandId(int id) { |
| 149 return id >= content_context_custom_first && | 164 return id >= content_context_custom_first && |
| 150 id <= content_context_custom_last; | 165 id <= content_context_custom_last; |
| 151 } | 166 } |
| 152 | 167 |
| 153 RenderViewContextMenuBase::RenderViewContextMenuBase( | 168 RenderViewContextMenuBase::RenderViewContextMenuBase( |
| 154 content::RenderFrameHost* render_frame_host, | 169 content::RenderFrameHost* render_frame_host, |
| 155 const content::ContextMenuParams& params) | 170 const content::ContextMenuParams& params) |
| 156 : params_(params), | 171 : params_(params), |
| 157 source_web_contents_(WebContents::FromRenderFrameHost(render_frame_host)), | 172 source_web_contents_(GetWebContentsToUse( |
| 173 WebContents::FromRenderFrameHost(render_frame_host))), | |
| 158 browser_context_(source_web_contents_->GetBrowserContext()), | 174 browser_context_(source_web_contents_->GetBrowserContext()), |
| 159 menu_model_(this), | 175 menu_model_(this), |
| 160 render_frame_id_(render_frame_host->GetRoutingID()), | 176 render_frame_id_(render_frame_host->GetRoutingID()), |
| 161 command_executed_(false), | 177 command_executed_(false), |
| 162 render_process_id_(render_frame_host->GetProcess()->GetID()) { | 178 render_process_id_(render_frame_host->GetProcess()->GetID()) { |
| 163 } | 179 } |
| 164 | 180 |
| 165 RenderViewContextMenuBase::~RenderViewContextMenuBase() { | 181 RenderViewContextMenuBase::~RenderViewContextMenuBase() { |
| 166 } | 182 } |
| 167 | 183 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 } | 396 } |
| 381 | 397 |
| 382 bool RenderViewContextMenuBase::IsCustomItemChecked(int id) const { | 398 bool RenderViewContextMenuBase::IsCustomItemChecked(int id) const { |
| 383 return IsCustomItemCheckedInternal(params_.custom_items, id); | 399 return IsCustomItemCheckedInternal(params_.custom_items, id); |
| 384 } | 400 } |
| 385 | 401 |
| 386 bool RenderViewContextMenuBase::IsCustomItemEnabled(int id) const { | 402 bool RenderViewContextMenuBase::IsCustomItemEnabled(int id) const { |
| 387 return IsCustomItemEnabledInternal(params_.custom_items, id); | 403 return IsCustomItemEnabledInternal(params_.custom_items, id); |
| 388 } | 404 } |
| 389 | 405 |
| OLD | NEW |