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 "extensions/browser/guest_view/guest_view_base.h" | 5 #include "extensions/browser/guest_view/guest_view_base.h" |
6 | 6 |
| 7 #include "base/i18n/rtl.h" |
7 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
9 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
10 #include "content/public/browser/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
11 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
13 #include "content/public/common/url_constants.h" | 14 #include "content/public/common/url_constants.h" |
14 #include "extensions/browser/api/extensions_api_client.h" | 15 #include "extensions/browser/api/extensions_api_client.h" |
15 #include "extensions/browser/event_router.h" | 16 #include "extensions/browser/event_router.h" |
16 #include "extensions/browser/extension_registry.h" | 17 #include "extensions/browser/extension_registry.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 : embedder_web_contents_(NULL), | 94 : embedder_web_contents_(NULL), |
94 embedder_render_process_id_(0), | 95 embedder_render_process_id_(0), |
95 browser_context_(browser_context), | 96 browser_context_(browser_context), |
96 guest_instance_id_(guest_instance_id), | 97 guest_instance_id_(guest_instance_id), |
97 view_instance_id_(guestview::kInstanceIDNone), | 98 view_instance_id_(guestview::kInstanceIDNone), |
98 initialized_(false), | 99 initialized_(false), |
99 auto_size_enabled_(false), | 100 auto_size_enabled_(false), |
100 weak_ptr_factory_(this) { | 101 weak_ptr_factory_(this) { |
101 } | 102 } |
102 | 103 |
| 104 base::string16 GuestViewBase::GetTaskTitle() const { |
| 105 return GetTitle(); |
| 106 } |
| 107 |
103 void GuestViewBase::Init(const std::string& embedder_extension_id, | 108 void GuestViewBase::Init(const std::string& embedder_extension_id, |
104 content::WebContents* embedder_web_contents, | 109 content::WebContents* embedder_web_contents, |
105 const base::DictionaryValue& create_params, | 110 const base::DictionaryValue& create_params, |
106 const WebContentsCreatedCallback& callback) { | 111 const WebContentsCreatedCallback& callback) { |
107 if (initialized_) | 112 if (initialized_) |
108 return; | 113 return; |
109 initialized_ = true; | 114 initialized_ = true; |
110 | 115 |
111 Feature* feature = FeatureProvider::GetAPIFeatures()->GetFeature( | 116 Feature* feature = FeatureProvider::GetAPIFeatures()->GetFeature( |
112 GetAPINamespace()); | 117 GetAPINamespace()); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 content::RenderViewHost* rvh = guest_web_contents()->GetRenderViewHost(); | 193 content::RenderViewHost* rvh = guest_web_contents()->GetRenderViewHost(); |
189 if (auto_size_enabled_) { | 194 if (auto_size_enabled_) { |
190 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); | 195 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); |
191 } else { | 196 } else { |
192 rvh->DisableAutoResize(element_size_); | 197 rvh->DisableAutoResize(element_size_); |
193 guest_size_ = element_size_; | 198 guest_size_ = element_size_; |
194 GuestSizeChangedDueToAutoSize(guest_size_, element_size_); | 199 GuestSizeChangedDueToAutoSize(guest_size_, element_size_); |
195 } | 200 } |
196 } | 201 } |
197 | 202 |
| 203 base::string16 GuestViewBase::GetTitle() const { |
| 204 // TODO(fsamuel): This code is essentially a copy-and-paste from |
| 205 // task_manager_util's GetTitleFromWebContents. We should reuse that code |
| 206 // once it's available in the extensions module. |
| 207 base::string16 title = guest_web_contents()->GetTitle(); |
| 208 if (title.empty()) { |
| 209 GURL url = guest_web_contents()->GetURL(); |
| 210 title = base::UTF8ToUTF16(url.spec()); |
| 211 // Force URL to be LTR. |
| 212 title = base::i18n::GetDisplayStringInLTRDirectionality(title); |
| 213 } else { |
| 214 // Since the tab_title will be concatenated with |
| 215 // IDS_TASK_MANAGER_TAB_PREFIX, we need to explicitly set the tab_title to |
| 216 // be LTR format if there is no strong RTL charater in it. Otherwise, if |
| 217 // IDS_TASK_MANAGER_TAB_PREFIX is an RTL word, the concatenated result |
| 218 // might be wrong. For example, http://mail.yahoo.com, whose title is |
| 219 // "Yahoo! Mail: The best web-based Email!", without setting it explicitly |
| 220 // as LTR format, the concatenated result will be "!Yahoo! Mail: The best |
| 221 // web-based Email :BAT", in which the capital letters "BAT" stands for |
| 222 // the Hebrew word for "tab". |
| 223 base::i18n::AdjustStringForLocaleDirection(&title); |
| 224 } |
| 225 return title; |
| 226 } |
| 227 |
198 // static | 228 // static |
199 void GuestViewBase::RegisterGuestViewType( | 229 void GuestViewBase::RegisterGuestViewType( |
200 const std::string& view_type, | 230 const std::string& view_type, |
201 const GuestCreationCallback& callback) { | 231 const GuestCreationCallback& callback) { |
202 GuestViewCreationMap::iterator it = | 232 GuestViewCreationMap::iterator it = |
203 guest_view_registry.Get().find(view_type); | 233 guest_view_registry.Get().find(view_type); |
204 DCHECK(it == guest_view_registry.Get().end()); | 234 DCHECK(it == guest_view_registry.Get().end()); |
205 guest_view_registry.Get()[view_type] = callback; | 235 guest_view_registry.Get()[view_type] = callback; |
206 } | 236 } |
207 | 237 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 guest_web_contents); | 469 guest_web_contents); |
440 callback.Run(guest_web_contents); | 470 callback.Run(guest_web_contents); |
441 } | 471 } |
442 | 472 |
443 // static | 473 // static |
444 void GuestViewBase::RegisterGuestViewTypes() { | 474 void GuestViewBase::RegisterGuestViewTypes() { |
445 ExtensionsAPIClient::Get()->RegisterGuestViewTypes(); | 475 ExtensionsAPIClient::Get()->RegisterGuestViewTypes(); |
446 } | 476 } |
447 | 477 |
448 } // namespace extensions | 478 } // namespace extensions |
OLD | NEW |