| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/ui/ime/ime_window.h" | 5 #include "chrome/browser/ui/ime/ime_window.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/ime/ime_native_window.h" | 9 #include "chrome/browser/ui/ime/ime_native_window.h" |
| 10 #include "chrome/browser/ui/ime/ime_window_observer.h" | 10 #include "chrome/browser/ui/ime/ime_window_observer.h" |
| 11 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.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/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 14 #include "extensions/common/constants.h" | 15 #include "extensions/common/constants.h" |
| 15 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
| 16 #include "extensions/common/manifest_handlers/icons_handler.h" | 17 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 17 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
| 18 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // The vertical margin between the cursor and the follow-cursor window. | 23 // The vertical margin between the cursor and the follow-cursor window. |
| 23 const int kFollowCursorMargin = 3; | 24 const int kFollowCursorMargin = 3; |
| 24 | 25 |
| 25 } // namespace | 26 } // namespace |
| 26 | 27 |
| 27 namespace ui { | 28 namespace ui { |
| 28 | 29 |
| 29 ImeWindow::ImeWindow(Profile* profile, | 30 ImeWindow::ImeWindow(Profile* profile, |
| 30 const extensions::Extension* extension, | 31 const extensions::Extension* extension, |
| 32 content::RenderFrameHost* opener_render_frame_host, |
| 31 const std::string& url, | 33 const std::string& url, |
| 32 Mode mode, | 34 Mode mode, |
| 33 const gfx::Rect& bounds) | 35 const gfx::Rect& bounds) |
| 34 : mode_(mode), native_window_(nullptr) { | 36 : mode_(mode), native_window_(nullptr) { |
| 35 if (extension) { // Allow nullable |extension| for testability. | 37 if (extension) { // Allow nullable |extension| for testability. |
| 36 title_ = extension->name(); | 38 title_ = extension->name(); |
| 37 icon_.reset(new extensions::IconImage( | 39 icon_.reset(new extensions::IconImage( |
| 38 profile, extension, extensions::IconsInfo::GetIcons(extension), | 40 profile, extension, extensions::IconsInfo::GetIcons(extension), |
| 39 extension_misc::EXTENSION_ICON_SMALL, gfx::ImageSkia(), this)); | 41 extension_misc::EXTENSION_ICON_SMALL, gfx::ImageSkia(), this)); |
| 40 } | 42 } |
| 41 | 43 |
| 42 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 44 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| 43 content::NotificationService::AllSources()); | 45 content::NotificationService::AllSources()); |
| 44 | 46 |
| 45 GURL gurl(url); | 47 GURL gurl(url); |
| 46 if (!gurl.is_valid()) | 48 if (!gurl.is_valid()) |
| 47 gurl = extension->GetResourceURL(url); | 49 gurl = extension->GetResourceURL(url); |
| 48 | 50 |
| 49 content::SiteInstance* instance = | 51 content::SiteInstance* site_instance = opener_render_frame_host |
| 50 content::SiteInstance::CreateForURL(profile, gurl); | 52 ? opener_render_frame_host->GetSiteInstance() : nullptr; |
| 51 content::WebContents::CreateParams create_params(profile, instance); | 53 if (!site_instance || |
| 54 site_instance->GetSiteURL().GetOrigin() != gurl.GetOrigin()) { |
| 55 site_instance = content::SiteInstance::CreateForURL(profile, gurl); |
| 56 } |
| 57 content::WebContents::CreateParams create_params(profile, site_instance); |
| 58 if (opener_render_frame_host) { |
| 59 create_params.opener_render_process_id = |
| 60 opener_render_frame_host->GetProcess()->GetID(); |
| 61 create_params.opener_render_frame_id = |
| 62 opener_render_frame_host->GetRoutingID(); |
| 63 } |
| 52 web_contents_.reset(content::WebContents::Create(create_params)); | 64 web_contents_.reset(content::WebContents::Create(create_params)); |
| 53 web_contents_->SetDelegate(this); | 65 web_contents_->SetDelegate(this); |
| 54 content::OpenURLParams params(gurl, content::Referrer(), SINGLETON_TAB, | 66 content::OpenURLParams params(gurl, content::Referrer(), SINGLETON_TAB, |
| 55 ui::PAGE_TRANSITION_LINK, false); | 67 ui::PAGE_TRANSITION_LINK, false); |
| 56 web_contents_->OpenURL(params); | 68 web_contents_->OpenURL(params); |
| 57 | 69 |
| 58 native_window_ = CreateNativeWindow(this, bounds, web_contents_.get()); | 70 native_window_ = CreateNativeWindow(this, bounds, web_contents_.get()); |
| 59 } | 71 } |
| 60 | 72 |
| 61 void ImeWindow::Show() { | 73 void ImeWindow::Show() { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 const gfx::Rect& pos) { | 169 const gfx::Rect& pos) { |
| 158 if (native_window_) | 170 if (native_window_) |
| 159 native_window_->SetBounds(pos); | 171 native_window_->SetBounds(pos); |
| 160 } | 172 } |
| 161 | 173 |
| 162 bool ImeWindow::IsPopupOrPanel(const content::WebContents* source) const { | 174 bool ImeWindow::IsPopupOrPanel(const content::WebContents* source) const { |
| 163 return true; | 175 return true; |
| 164 } | 176 } |
| 165 | 177 |
| 166 } // namespace ui | 178 } // namespace ui |
| OLD | NEW |