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

Side by Side Diff: content/public/common/content_client.cc

Issue 9623027: Move --user-agent overriding logic from chrome into content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: replace SetContentClient() with Initialize() Created 8 years, 8 months 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/public/common/content_client.h" 5 #include "content/public/common/content_client.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_piece.h" 8 #include "base/string_piece.h"
9 #include "base/string_util.h"
9 #include "webkit/glue/webkit_glue.h" 10 #include "webkit/glue/webkit_glue.h"
10 #include "webkit/plugins/ppapi/host_globals.h" 11 #include "webkit/plugins/ppapi/host_globals.h"
11 12
12 namespace content { 13 namespace content {
13 14
14 static ContentClient* g_client; 15 static ContentClient* g_client;
15 16
16 void SetContentClient(ContentClient* client) { 17 void Initialize(ContentClient* client, const std::string& user_agent) {
18 DCHECK(client);
17 g_client = client; 19 g_client = client;
20 webkit_glue::SetUserAgent(user_agent, false);
21 }
18 22
19 // TODO(dpranke): Doing real work (calling webkit_glue::SetUserAgent) 23 void Uninitialize() {
20 // inside what looks like a function that initializes a global is a 24 DCHECK(g_client);
21 // bit odd, but we need to make sure this is done before 25 g_client = NULL;
22 // webkit_glue::GetUserAgent() is called (so that the UA doesn't change). 26 webkit_glue::SetUserAgent(EmptyString(), false);
23 //
24 // It would be cleaner if we could rename this to something like a
25 // content::Initialize(). Maybe we can merge this into ContentMain() somehow?
26 if (client) {
27 bool custom = false;
28 std::string ua = client->GetUserAgent(&custom);
29 webkit_glue::SetUserAgent(ua, custom);
30 }
31 } 27 }
32 28
33 ContentClient* GetContentClient() { 29 ContentClient* GetContentClient() {
30 DCHECK(g_client);
34 return g_client; 31 return g_client;
35 } 32 }
36 33
37 const std::string& GetUserAgent(const GURL& url) { 34 const std::string& GetUserAgent(const GURL& url) {
38 DCHECK(g_client); 35 DCHECK(g_client);
39 return webkit_glue::GetUserAgent(url); 36 return webkit_glue::GetUserAgent(url);
40 } 37 }
41 38
42 webkit::ppapi::HostGlobals* GetHostGlobals() { 39 webkit::ppapi::HostGlobals* GetHostGlobals() {
43 return webkit::ppapi::HostGlobals::Get(); 40 return webkit::ppapi::HostGlobals::Get();
44 } 41 }
45 42
46 ContentClient::ContentClient() 43 ContentClient::ContentClient()
47 : browser_(NULL), plugin_(NULL), renderer_(NULL), utility_(NULL) { 44 : browser_(NULL), plugin_(NULL), renderer_(NULL), utility_(NULL) {
48 } 45 }
49 46
50 ContentClient::~ContentClient() { 47 ContentClient::~ContentClient() {
51 } 48 }
52 49
53 } // namespace content 50 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698