Lưu ý rằng chúng ta có thể chỉ định rõ ràng định dạng mimetype của file ví dụ text/html, application/xhtml+xml và chế độ Encoding mặc định, khuyến cáo ở đây là html và utf-8: The S
Trang 1Tìm hiểu về file config.xml trong
extension Opera – P.2
Trang 2File khởi đầu mà extension sử dụng khi tải file index.html, nhưng nếu muốn
sử dụng file khác thì thay đổi phần <content> bên trong Lưu ý rằng chúng ta
có thể chỉ định rõ ràng định dạng mimetype của file (ví dụ text/html,
application/xhtml+xml) và chế độ Encoding mặc định, khuyến cáo ở đây là html và utf-8:
<widget xmlns="http://www.w3.org/ns/widgets"
id="http://example.org/disco"
version="1.0"
width="600"
height="400">
<name short="Disco" xml:lang="en">The Saturday Night Disco
Machine</name>
<description xml:lang="en">
This extension will help you to select all
the movements you need to know to be the King of Disco
You can select a specific steps sequence and view the
associated video.</description>
Trang 3<author href="http://example.org/tony/"
email="tony@example.org">
Tony Manero
</author>
<license href="http://www.opensource.org/licenses/mit-license.php"> Licensed under the MIT license
</license>
<icon src="img/disco-ball.png"/>
<icon src="img/disco-ball.svg" width="50" height="50"/>
<content src="index.html" type="text/html" encoding="utf-8"/>
</widget>
Thiết lập Preference mặc định:
Thực tế, việc này được thực hiện bằng cách điều chỉnh thành phần
<preference> Mỗi phần đều phải chứa tên và giá trị khởi tạo mặc định, được
lưu trữ trong thuộc tính name và value, hoặc khóa phần giá trị này bằng cách
thêm tùy chọn readonly="true" Những thông số này được tổng quát bằng thuộc tính widget.preferences:
Trang 4<widget xmlns="http://www.w3.org/ns/widgets"
id="http://example.org/disco"
version="1.0"
width="600"
height="400">
<name short="Disco" xml:lang="en">The Saturday Night Disco Machine</name>
<description xml:lang="en">
This extension will help you to select all
the movements you need to know to be the King of Disco
You can select a specific steps sequence and view the
associated video.</description>
<author href="http://example.org/tony/"
email="tony@example.org">
Tony Manero
</author>
<license href="http://www.opensource.org/licenses/mit-license.php"> Licensed under the MIT license
</license>
Trang 5<icon src="img/disco-ball.png"/>
<icon src="img/disco-ball.svg" width="50" height="50"/>
<content src="index.html" type="text/html" encoding="utf-8"/>
<preference name="step"
value="beegees"/>
<preference name="mood"
value="cheesy"
readonly="true"/>
</widget>
Với extension Speed Dial:
Nếu muốn tạo extension Speed Dial thì cần phải chú ý tới một vài điều sau, thiết lập thuộc tính viewmodes trong thẻ <widget> thành minimized.Bên cạnh đó, thay đổi thẻ <feature> với thuộc tính name thành opera:speeddial, khởi tạo giá trị phù hợp cho required Cuối cùng, gán thêm thẻ <param> với thuộc tính name thành url, còn value thành đường dẫn URL mà extension
Speed Dial sẽ trỏ tới Ví dụ như sau:
<widget xmlns="http://www.w3.org/ns/widgets"
id=http://example.org/disco"
Trang 6version="1.0" viewmodes="minimized">
<name short="Disco" xml:lang="en">The Saturday Night Disco Machine</name>
<description xml:lang="en">
This extension will help you to select all
the movements you need to know to be the King of Disco
You can select a specific steps sequence and view the
associated video.</description>
<author href="http://example.org/tony/"
email="tony@example.org">
Tony Manero
</author>
<feature name="opera:speeddial" required="false">
<param name="url" value="http://en.wikipedia.org/wiki/Disco"/>
</feature>
</widget>
Thiết lập chế độ chia sẻ cookies:
Trang 7Về cơ chế hoạt động thì extension thường xuyên làm việc trong môi trường riêng biệt với cookies đi kèm Tuy nhiên, trong 1 số trường hợp đặc biệt thì
có thể chúng ta sẽ muốn extension chia sẻ cookies với nội dung của trình duyệt đang hiển thị và ứng dụng web Để thực hiện, các bạn hãy gán thêm thẻ
<feature> với thuộc tính name thành opera:sharecookies và giá trị phù hợp dành cho phần required Sau đó, thêm thẻ <access> với giá trị origin là
đường dẫn URL của website muốn chia sẻ cookies Còn nếu muốn truy cập
tới subdomain của website đó thì chỉ cần thêm thuộc tính subdomains tới phần <feature> và thiết lập giá trị thành true Ví dụ:
<widget xmlns="http://www.w3.org/ns/widgets"
id="http://example.org/disco"
version="1.0">
<name short="Disco" xml:lang="en">The Saturday Night Disco
Machine</name>
<description xml:lang="en">
This extension will help you to select all
the movements you need to know to be the King of Disco
You can select a specific steps sequence and view the
Trang 8associated video.</description>
<author href="http://example.org/tony/"
email="tony@example.org">
Tony Manero
</author>
<! request for cookie sharing to be enabled in this extension >
<feature name="opera:share-cookies" required="true"/>
<! list of domains on which cookie sharing will be enabled > <access origin="http://facebook.com" subdomains="true"/>
</widget>
Chính sách bảo mật:
Cuối cùng là công đoạn khai báo các chính sách quyền truy cập đối với từng thành phần trong widget, và widget sẽ không thể hoạt động nếu thiếu thông tin này Ở bên trên, chúng ta đã xác định được domain trong phần ID, và tại đây các bạn cần kiểm tra đầy đủ domain chính cũng như subdomain có liên quan Ví dụ như sau:
<widget xmlns="http://www.w3.org/ns/widgets"
id="http://example.org/disco"
Trang 9version="1.0"
width="600"
height="400">
<name short="Disco" xml:lang="en">The Saturday Night Disco Machine</name>
<description xml:lang="en">
This extension will help you to select all
the movements you need to know to be the King of Disco
You can select a specific steps sequence and view the
associated video.</description>
<author href="http://example.org/tony/"
email="tony@example.org">
Tony Manero
</author>
<license href="http://www.opensource.org/licenses/mit-license.php"> Licensed under the MIT license
</license>
<icon src="img/disco-ball.png"/>
<icon src="img/disco-ball.svg" width="50" height="50"/>
Trang 10<content src="index.html" type="text/html" encoding="utf-8"/>
<preference name="step"
value="beegees"/>
<preference name="mood"
value="cheesy"
readonly="true"/>
<access origin="http://example.org" subdomains="true"/>
</widget>
Sau khi hoàn tất file config.xml, hãy kiểm tra lại toàn bộ các thiết lập, thông
số cũng như điều kiện tối thiểu một lần nữa để đảm bảo rằng extension sẽ hoạt động ổn định
config.xml nằm trong thư mục gốc của extension
config.xml được viết bằng chữ thường
config.xml là file text thông thường
Thành phần cơ bản là widget
Phần widget có thuộc tính xmlns="http://www.w3.org/ns/widgets"
Giá trị true và false phải được biết bằng chữ thường
Giá trị language được viết bằng chữ thường
Trang 11 config.xml được lưu dưới chế độ encode utf-8
Với extension Speed Dial, thẻ <widget> có giá trị viewmodes là
minimized, đồng thời file config.xml có chứa thẻ <feature> và
<param> với giá trị thuộc tính phù hợp
Nếu chia sẻ cookies thì file config.xml phải chứa thẻ <feature> và
<access> với giá trị phù hợp
File config.xml có chứa các thành phần dùng để chỉ định khả năng truy cập đi kèm với chính sách – policy được thiết lập rõ ràng
Bên cạnh đó, các bạn có thể tìm hiểu thêm một số khái niệm có liên quan tại đây:
Chúc các bạn thành công!