1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/browser/view_type_utils.h"
7 #include "base/lazy_instance.h"
8 #include "content/public/browser/web_contents.h"
9 #include "extensions/browser/extensions_browser_client.h"
11 using content::WebContents
;
13 namespace extensions
{
17 const char kViewTypeUserDataKey
[] = "ViewTypeUserData";
19 class ViewTypeUserData
: public base::SupportsUserData::Data
{
21 explicit ViewTypeUserData(ViewType type
) : type_(type
) {}
22 ~ViewTypeUserData() override
{}
23 ViewType
type() { return type_
; }
31 ViewType
GetViewType(WebContents
* tab
) {
33 return VIEW_TYPE_INVALID
;
35 ViewTypeUserData
* user_data
= static_cast<ViewTypeUserData
*>(
36 tab
->GetUserData(&kViewTypeUserDataKey
));
38 return user_data
? user_data
->type() : VIEW_TYPE_INVALID
;
41 void SetViewType(WebContents
* tab
, ViewType type
) {
42 tab
->SetUserData(&kViewTypeUserDataKey
, new ViewTypeUserData(type
));
44 ExtensionsBrowserClient::Get()->AttachExtensionTaskManagerTag(tab
, type
);
47 } // namespace extensions