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

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

Issue 4506002: Make sure the app section opens whenever a new apps is (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment cleanup Created 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/dom_ui/shown_sections_handler.h ('k') | chrome/browser/resources/ntp/apps.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/dom_ui/shown_sections_handler.h" 5 #include "chrome/browser/dom_ui/shown_sections_handler.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/metrics/user_metrics.h" 11 #include "chrome/browser/metrics/user_metrics.h"
12 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/profile.h" 13 #include "chrome/browser/profile.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
16 #include "chrome/common/notification_details.h" 16 #include "chrome/common/notification_details.h"
17 #include "chrome/common/notification_source.h"
17 #include "chrome/common/notification_type.h" 18 #include "chrome/common/notification_type.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 20
20 namespace { 21 namespace {
21 22
22 // Will cause an UMA notification if the mode of the new tab page 23 // Will cause an UMA notification if the mode of the new tab page
23 // was changed to hide/show the most visited thumbnails. 24 // was changed to hide/show the most visited thumbnails.
24 // TODO(aa): Needs to be updated to match newest NTP - http://crbug.com/57440 25 // TODO(aa): Needs to be updated to match newest NTP - http://crbug.com/57440
25 void NotifySectionDisabled(int new_mode, int old_mode, Profile *profile) { 26 void NotifySectionDisabled(int new_mode, int old_mode, Profile *profile) {
26 // If the oldmode HAD either thumbs or lists visible. 27 // If the oldmode HAD either thumbs or lists visible.
(...skipping 15 matching lines...) Expand all
42 43
43 } // namespace 44 } // namespace
44 45
45 // static 46 // static
46 int ShownSectionsHandler::GetShownSections(PrefService* prefs) { 47 int ShownSectionsHandler::GetShownSections(PrefService* prefs) {
47 return prefs->GetInteger(prefs::kNTPShownSections); 48 return prefs->GetInteger(prefs::kNTPShownSections);
48 } 49 }
49 50
50 ShownSectionsHandler::ShownSectionsHandler(PrefService* pref_service) 51 ShownSectionsHandler::ShownSectionsHandler(PrefService* pref_service)
51 : pref_service_(pref_service) { 52 : pref_service_(pref_service) {
52 registrar_.Init(pref_service); 53 pref_registrar_.Init(pref_service);
53 registrar_.Add(prefs::kNTPShownSections, this); 54 pref_registrar_.Add(prefs::kNTPShownSections, this);
54 } 55 }
55 56
56 void ShownSectionsHandler::RegisterMessages() { 57 void ShownSectionsHandler::RegisterMessages() {
58 notification_registrar_.Add(this, NotificationType::EXTENSION_INSTALLED,
59 Source<Profile>(dom_ui_->GetProfile()));
60
57 dom_ui_->RegisterMessageCallback("getShownSections", 61 dom_ui_->RegisterMessageCallback("getShownSections",
58 NewCallback(this, &ShownSectionsHandler::HandleGetShownSections)); 62 NewCallback(this, &ShownSectionsHandler::HandleGetShownSections));
59 dom_ui_->RegisterMessageCallback("setShownSections", 63 dom_ui_->RegisterMessageCallback("setShownSections",
60 NewCallback(this, &ShownSectionsHandler::HandleSetShownSections)); 64 NewCallback(this, &ShownSectionsHandler::HandleSetShownSections));
61 } 65 }
62 66
63 void ShownSectionsHandler::Observe(NotificationType type, 67 void ShownSectionsHandler::Observe(NotificationType type,
64 const NotificationSource& source, 68 const NotificationSource& source,
65 const NotificationDetails& details) { 69 const NotificationDetails& details) {
66 DCHECK(NotificationType::PREF_CHANGED == type); 70 if (type == NotificationType::PREF_CHANGED) {
67 std::string* pref_name = Details<std::string>(details).ptr(); 71 std::string* pref_name = Details<std::string>(details).ptr();
68 DCHECK(*pref_name == prefs::kNTPShownSections); 72 DCHECK(*pref_name == prefs::kNTPShownSections);
73 int sections = pref_service_->GetInteger(prefs::kNTPShownSections);
74 FundamentalValue sections_value(sections);
75 dom_ui_->CallJavascriptFunction(L"setShownSections", sections_value);
76 } else if (type == NotificationType::EXTENSION_INSTALLED) {
77 if (Details<const Extension>(details).ptr()->is_app()) {
78 int mode = pref_service_->GetInteger(prefs::kNTPShownSections);
69 79
70 int sections = pref_service_->GetInteger(prefs::kNTPShownSections); 80 // De-minimize the apps section.
71 FundamentalValue sections_value(sections); 81 mode &= ~MINIMIZED_APPS;
72 dom_ui_->CallJavascriptFunction(L"setShownSections", sections_value); 82
83 // Hide any open sections.
Erik does not do reviews 2010/11/04 23:40:39 Shouldn't this be "minimize" rather than "hide"?
Aaron Boodman 2010/11/05 00:08:34 The nomenclature in NTP is all messed up. We unfor
84 mode &= ~ALL_SECTIONS_MASK;
85
86 // Show the apps section.
87 mode |= APPS;
88
89 pref_service_->SetInteger(prefs::kNTPShownSections, mode);
90 }
91 } else {
92 NOTREACHED();
93 }
73 } 94 }
74 95
75 void ShownSectionsHandler::HandleGetShownSections(const ListValue* args) { 96 void ShownSectionsHandler::HandleGetShownSections(const ListValue* args) {
76 int sections = GetShownSections(pref_service_); 97 int sections = GetShownSections(pref_service_);
77 FundamentalValue sections_value(sections); 98 FundamentalValue sections_value(sections);
78 dom_ui_->CallJavascriptFunction(L"onShownSections", sections_value); 99 dom_ui_->CallJavascriptFunction(L"onShownSections", sections_value);
79 } 100 }
80 101
81 void ShownSectionsHandler::HandleSetShownSections(const ListValue* args) { 102 void ShownSectionsHandler::HandleSetShownSections(const ListValue* args) {
82 int mode; 103 int mode;
(...skipping 26 matching lines...) Expand all
109 shown_sections = APPS; 130 shown_sections = APPS;
110 else 131 else
111 shown_sections = THUMB; 132 shown_sections = THUMB;
112 133
113 changed = true; 134 changed = true;
114 } 135 }
115 136
116 if (changed) 137 if (changed)
117 pref_service->SetInteger(prefs::kNTPShownSections, shown_sections); 138 pref_service->SetInteger(prefs::kNTPShownSections, shown_sections);
118 } 139 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/shown_sections_handler.h ('k') | chrome/browser/resources/ntp/apps.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698