• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that can
3 // be found in the LICENSE file.
4 
5 #ifndef CEF_LIBCEF_BROWSER_NET_INTERNAL_SCHEME_HANDLER_H_
6 #define CEF_LIBCEF_BROWSER_NET_INTERNAL_SCHEME_HANDLER_H_
7 #pragma once
8 
9 #include <string>
10 
11 #include "include/cef_scheme.h"
12 
13 #include "base/memory/ref_counted_memory.h"
14 #include "url/gurl.h"
15 
16 namespace scheme {
17 
18 // All methods will be called on the browser process IO thread.
19 class InternalHandlerDelegate {
20  public:
21   class Action {
22    public:
23     Action();
24 
25     // Set to the appropriate value or leave empty to have it determined based
26     // on the file extension.
27     std::string mime_type;
28 
29     // Option 1: Provide a stream for the resource contents. Set |stream_size|
30     // to the stream size or to -1 if unknown.
31     CefRefPtr<CefStreamReader> stream;
32     int stream_size;
33 
34     // Option 2: Provide a base::RefCountedMemory for the resource contents.
35     scoped_refptr<base::RefCountedMemory> bytes;
36 
37     // Option 3: Specify a resource id to load static content.
38     int resource_id;
39 
40     // Option 4: Redirect to the specified URL.
41     GURL redirect_url;
42   };
43 
~InternalHandlerDelegate()44   virtual ~InternalHandlerDelegate() {}
45 
46   // Populate |action| and return true if the request was handled.
47   virtual bool OnRequest(CefRefPtr<CefBrowser> browser,
48                          CefRefPtr<CefRequest> request,
49                          Action* action) = 0;
50 };
51 
52 // Create an internal scheme handler factory. The factory will take ownership of
53 // |delegate|.
54 CefRefPtr<CefSchemeHandlerFactory> CreateInternalHandlerFactory(
55     std::unique_ptr<InternalHandlerDelegate> delegate);
56 
57 }  // namespace scheme
58 
59 #endif  // CEF_LIBCEF_BROWSER_NET_INTERNAL_SCHEME_HANDLER_H_
60