| 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 in a MimeHandlerViewGuest, use its embedder WebContents. |
| 134 #if defined(ENABLE_EXTENSIONS) |
| 135 auto guest_view = |
| 136 extensions::MimeHandlerViewGuest::FromWebContents(web_contents); |
| 137 if (guest_view) |
| 138 return guest_view->embedder_web_contents(); |
| 139 #endif |
| 140 return web_contents; |
| 141 } |
| 142 |
| 129 } // namespace | 143 } // namespace |
| 130 | 144 |
| 131 // static | 145 // static |
| 132 void RenderViewContextMenuBase::SetContentCustomCommandIdRange( | 146 void RenderViewContextMenuBase::SetContentCustomCommandIdRange( |
| 133 int first, int last) { | 147 int first, int last) { |
| 134 // The range is inclusive. | 148 // The range is inclusive. |
| 135 content_context_custom_first = first; | 149 content_context_custom_first = first; |
| 136 content_context_custom_last = last; | 150 content_context_custom_last = last; |
| 137 } | 151 } |
| 138 | 152 |
| 139 // static | 153 // static |
| 140 const size_t RenderViewContextMenuBase::kMaxSelectionTextLength = 50; | 154 const size_t RenderViewContextMenuBase::kMaxSelectionTextLength = 50; |
| 141 | 155 |
| 142 // static | 156 // static |
| 143 int RenderViewContextMenuBase::ConvertToContentCustomCommandId(int id) { | 157 int RenderViewContextMenuBase::ConvertToContentCustomCommandId(int id) { |
| 144 return content_context_custom_first + id; | 158 return content_context_custom_first + id; |
| 145 } | 159 } |
| 146 | 160 |
| 147 // static | 161 // static |
| 148 bool RenderViewContextMenuBase::IsContentCustomCommandId(int id) { | 162 bool RenderViewContextMenuBase::IsContentCustomCommandId(int id) { |
| 149 return id >= content_context_custom_first && | 163 return id >= content_context_custom_first && |
| 150 id <= content_context_custom_last; | 164 id <= content_context_custom_last; |
| 151 } | 165 } |
| 152 | 166 |
| 153 RenderViewContextMenuBase::RenderViewContextMenuBase( | 167 RenderViewContextMenuBase::RenderViewContextMenuBase( |
| 154 content::RenderFrameHost* render_frame_host, | 168 content::RenderFrameHost* render_frame_host, |
| 155 const content::ContextMenuParams& params) | 169 const content::ContextMenuParams& params) |
| 156 : params_(params), | 170 : params_(params), |
| 157 source_web_contents_(WebContents::FromRenderFrameHost(render_frame_host)), | 171 source_web_contents_(GetWebContentsToUse( |
| 172 WebContents::FromRenderFrameHost(render_frame_host))), |
| 158 browser_context_(source_web_contents_->GetBrowserContext()), | 173 browser_context_(source_web_contents_->GetBrowserContext()), |
| 159 menu_model_(this), | 174 menu_model_(this), |
| 160 render_frame_id_(render_frame_host->GetRoutingID()), | 175 render_frame_id_(render_frame_host->GetRoutingID()), |
| 161 command_executed_(false), | 176 command_executed_(false), |
| 162 render_process_id_(render_frame_host->GetProcess()->GetID()) { | 177 render_process_id_(render_frame_host->GetProcess()->GetID()) { |
| 163 } | 178 } |
| 164 | 179 |
| 165 RenderViewContextMenuBase::~RenderViewContextMenuBase() { | 180 RenderViewContextMenuBase::~RenderViewContextMenuBase() { |
| 166 } | 181 } |
| 167 | 182 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 } | 395 } |
| 381 | 396 |
| 382 bool RenderViewContextMenuBase::IsCustomItemChecked(int id) const { | 397 bool RenderViewContextMenuBase::IsCustomItemChecked(int id) const { |
| 383 return IsCustomItemCheckedInternal(params_.custom_items, id); | 398 return IsCustomItemCheckedInternal(params_.custom_items, id); |
| 384 } | 399 } |
| 385 | 400 |
| 386 bool RenderViewContextMenuBase::IsCustomItemEnabled(int id) const { | 401 bool RenderViewContextMenuBase::IsCustomItemEnabled(int id) const { |
| 387 return IsCustomItemEnabledInternal(params_.custom_items, id); | 402 return IsCustomItemEnabledInternal(params_.custom_items, id); |
| 388 } | 403 } |
| 389 | 404 |
| OLD | NEW |