Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Side by Side Diff: chrome/browser/browser.cc

Issue 399045: Set prop app id for chromium/application shortcut. (Closed)
Patch Set: more for hbono Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/browser.h" 5 #include "chrome/browser/browser.h"
6 6
7 #include "app/animation.h" 7 #include "app/animation.h"
8 #include "app/l10n_util.h" 8 #include "app/l10n_util.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/gfx/point.h" 10 #include "base/gfx/point.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "chrome/browser/sessions/session_service.h" 43 #include "chrome/browser/sessions/session_service.h"
44 #include "chrome/browser/sessions/session_types.h" 44 #include "chrome/browser/sessions/session_types.h"
45 #include "chrome/browser/sessions/tab_restore_service.h" 45 #include "chrome/browser/sessions/tab_restore_service.h"
46 #include "chrome/browser/status_bubble.h" 46 #include "chrome/browser/status_bubble.h"
47 #include "chrome/browser/sync/profile_sync_service.h" 47 #include "chrome/browser/sync/profile_sync_service.h"
48 #include "chrome/browser/tab_contents/interstitial_page.h" 48 #include "chrome/browser/tab_contents/interstitial_page.h"
49 #include "chrome/browser/tab_contents/navigation_controller.h" 49 #include "chrome/browser/tab_contents/navigation_controller.h"
50 #include "chrome/browser/tab_contents/navigation_entry.h" 50 #include "chrome/browser/tab_contents/navigation_entry.h"
51 #include "chrome/browser/tab_contents/tab_contents.h" 51 #include "chrome/browser/tab_contents/tab_contents.h"
52 #include "chrome/browser/tab_contents/tab_contents_view.h" 52 #include "chrome/browser/tab_contents/tab_contents_view.h"
53 #include "chrome/browser/web_applications/web_app.h"
53 #include "chrome/browser/window_sizer.h" 54 #include "chrome/browser/window_sizer.h"
54 #include "chrome/common/chrome_constants.h" 55 #include "chrome/common/chrome_constants.h"
55 #include "chrome/common/chrome_switches.h" 56 #include "chrome/common/chrome_switches.h"
56 #include "chrome/common/extensions/extension.h" 57 #include "chrome/common/extensions/extension.h"
57 #include "chrome/common/notification_service.h" 58 #include "chrome/common/notification_service.h"
58 #include "chrome/common/page_transition_types.h" 59 #include "chrome/common/page_transition_types.h"
59 #include "chrome/common/platform_util.h" 60 #include "chrome/common/platform_util.h"
60 #include "chrome/common/pref_names.h" 61 #include "chrome/common/pref_names.h"
61 #include "chrome/common/pref_service.h" 62 #include "chrome/common/pref_service.h"
62 #include "chrome/common/url_constants.h" 63 #include "chrome/common/url_constants.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 227
227 if (SupportsWindowFeature(FEATURE_EXTENSIONSHELF)) 228 if (SupportsWindowFeature(FEATURE_EXTENSIONSHELF))
228 extension_shelf_model_.reset(new ExtensionShelfModel(this)); 229 extension_shelf_model_.reset(new ExtensionShelfModel(this));
229 230
230 window_ = BrowserWindow::CreateBrowserWindow(this); 231 window_ = BrowserWindow::CreateBrowserWindow(this);
231 232
232 #if defined(OS_WIN) 233 #if defined(OS_WIN)
233 // Set the app user model id for this application to that of the application 234 // Set the app user model id for this application to that of the application
234 // name. See http://crbug.com/7028. 235 // name. See http://crbug.com/7028.
235 win_util::SetAppIdForWindow(type_ & TYPE_APP ? app_name_ : 236 win_util::SetAppIdForWindow(type_ & TYPE_APP ? app_name_ :
236 l10n_util::GetString(IDS_PRODUCT_NAME), 237 std::wstring(chrome::kBrowserAppId),
237 window()->GetNativeHandle()); 238 window()->GetNativeHandle());
238 #endif 239 #endif
239 240
240 NotificationService::current()->Notify( 241 NotificationService::current()->Notify(
241 NotificationType::BROWSER_WINDOW_READY, 242 NotificationType::BROWSER_WINDOW_READY,
242 Source<Browser>(this), 243 Source<Browser>(this),
243 NotificationService::NoDetails()); 244 NotificationService::NoDetails());
244 245
245 // Show the First Run information bubble if we've been told to. 246 // Show the First Run information bubble if we've been told to.
246 PrefService* local_state = g_browser_process->local_state(); 247 PrefService* local_state = g_browser_process->local_state();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 if (!browser) 311 if (!browser)
311 browser = Browser::Create(off_the_record_profile); 312 browser = Browser::Create(off_the_record_profile);
312 // TODO(eroman): should we have referrer here? 313 // TODO(eroman): should we have referrer here?
313 browser->AddTabWithURL(url, GURL(), PageTransition::LINK, true, -1, false, 314 browser->AddTabWithURL(url, GURL(), PageTransition::LINK, true, -1, false,
314 NULL); 315 NULL);
315 browser->window()->Show(); 316 browser->window()->Show();
316 } 317 }
317 318
318 // static 319 // static
319 void Browser::OpenApplicationWindow(Profile* profile, const GURL& url) { 320 void Browser::OpenApplicationWindow(Profile* profile, const GURL& url) {
320 std::wstring app_name = ComputeApplicationNameFromURL(url); 321 std::wstring app_name = web_app::GenerateApplicationNameFromURL(url);
321 RegisterAppPrefs(app_name); 322 RegisterAppPrefs(app_name);
322 323
323 Browser* browser = Browser::CreateForApp(app_name, profile, false); 324 Browser* browser = Browser::CreateForApp(app_name, profile, false);
324 browser->AddTabWithURL(url, GURL(), PageTransition::START_PAGE, true, -1, 325 browser->AddTabWithURL(url, GURL(), PageTransition::START_PAGE, true, -1,
325 false, NULL); 326 false, NULL);
326 327
327 TabContents* tab_contents = browser->GetSelectedTabContents(); 328 TabContents* tab_contents = browser->GetSelectedTabContents();
328 tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 329 tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
329 tab_contents->render_view_host()->SyncRendererPrefs(); 330 tab_contents->render_view_host()->SyncRendererPrefs();
330 browser->window()->Show(); 331 browser->window()->Show();
(...skipping 1754 matching lines...) Expand 10 before | Expand all | Expand 10 after
2085 NotificationService::NoDetails()); 2086 NotificationService::NoDetails());
2086 return false; 2087 return false;
2087 } 2088 }
2088 2089
2089 bool Browser::IsApplication() const { 2090 bool Browser::IsApplication() const {
2090 return (type_ & TYPE_APP) != 0; 2091 return (type_ & TYPE_APP) != 0;
2091 } 2092 }
2092 2093
2093 void Browser::ConvertContentsToApplication(TabContents* contents) { 2094 void Browser::ConvertContentsToApplication(TabContents* contents) {
2094 const GURL& url = contents->controller().GetActiveEntry()->url(); 2095 const GURL& url = contents->controller().GetActiveEntry()->url();
2095 std::wstring app_name = ComputeApplicationNameFromURL(url); 2096 std::wstring app_name = web_app::GenerateApplicationNameFromURL(url);
2096 RegisterAppPrefs(app_name); 2097 RegisterAppPrefs(app_name);
2097 2098
2098 DetachContents(contents); 2099 DetachContents(contents);
2099 Browser* browser = Browser::CreateForApp(app_name, profile_, false); 2100 Browser* browser = Browser::CreateForApp(app_name, profile_, false);
2100 browser->tabstrip_model()->AppendTabContents(contents, true); 2101 browser->tabstrip_model()->AppendTabContents(contents, true);
2101 TabContents* tab_contents = browser->GetSelectedTabContents(); 2102 TabContents* tab_contents = browser->GetSelectedTabContents();
2102 tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 2103 tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
2103 tab_contents->render_view_host()->SyncRendererPrefs(); 2104 tab_contents->render_view_host()->SyncRendererPrefs();
2104 browser->window()->Show(); 2105 browser->window()->Show();
2105 } 2106 }
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after
3018 forward_direction, 3019 forward_direction,
3019 false); // Not case sensitive. 3020 false); // Not case sensitive.
3020 } 3021 }
3021 } 3022 }
3022 3023
3023 void Browser::CloseFrame() { 3024 void Browser::CloseFrame() {
3024 window_->Close(); 3025 window_->Close();
3025 } 3026 }
3026 3027
3027 // static 3028 // static
3028 std::wstring Browser::ComputeApplicationNameFromURL(const GURL& url) {
3029 std::string t;
3030 t.append(url.host());
3031 t.append("_");
3032 t.append(url.path());
3033 return UTF8ToWide(t);
3034 }
3035
3036 // static
3037 void Browser::RegisterAppPrefs(const std::wstring& app_name) { 3029 void Browser::RegisterAppPrefs(const std::wstring& app_name) {
3038 // A set of apps that we've already started. 3030 // A set of apps that we've already started.
3039 static std::set<std::wstring>* g_app_names = NULL; 3031 static std::set<std::wstring>* g_app_names = NULL;
3040 3032
3041 if (!g_app_names) 3033 if (!g_app_names)
3042 g_app_names = new std::set<std::wstring>; 3034 g_app_names = new std::set<std::wstring>;
3043 3035
3044 // Only register once for each app name. 3036 // Only register once for each app name.
3045 if (g_app_names->find(app_name) != g_app_names->end()) 3037 if (g_app_names->find(app_name) != g_app_names->end())
3046 return; 3038 return;
(...skipping 12 matching lines...) Expand all
3059 /////////////////////////////////////////////////////////////////////////////// 3051 ///////////////////////////////////////////////////////////////////////////////
3060 // BrowserToolbarModel (private): 3052 // BrowserToolbarModel (private):
3061 3053
3062 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { 3054 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() {
3063 // This |current_tab| can be NULL during the initialization of the 3055 // This |current_tab| can be NULL during the initialization of the
3064 // toolbar during window creation (i.e. before any tabs have been added 3056 // toolbar during window creation (i.e. before any tabs have been added
3065 // to the window). 3057 // to the window).
3066 TabContents* current_tab = browser_->GetSelectedTabContents(); 3058 TabContents* current_tab = browser_->GetSelectedTabContents();
3067 return current_tab ? &current_tab->controller() : NULL; 3059 return current_tab ? &current_tab->controller() : NULL;
3068 } 3060 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698